CocosCreator 自定義腳本


版本:3.3.1

參考: cocos文檔-腳本創建

 

一  復制引擎路徑下的ts模板文件

C:\CocosDashboard_1.0.12\resources\.editors\Creator\3.3.1\resources\resources\3d\engine\editor\assets\default_file_content\ts

ts:

import { _decorator, Component, Node } from 'cc';
const { ccclass, property } = _decorator;

/**
 * Predefined variables
 * Name = <%Name%>
 * DateTime = <%DateTime%>
 * Author = <%Author%>
 * FileBasename = <%FileBasename%>
 * FileBasenameNoExtension = <%FileBasenameNoExtension%>
 * URL = <%URL%>
 * ManualUrl = <%ManualUrl%>
 *
 */
 
@ccclass('<%Name%>')
export class <%Name%> extends Component {
    // [1]
    // dummy = '';

    // [2]
    // @property
    // serializableDummy = 0;

    start () {
        // [3]
    }

    // update (deltaTime: number) {
    //     // [4]
    // }
}

/**
 * [1] Class member could be defined like this.
 * [2] Use `property` decorator if your want the member to be serializable.
 * [3] Your initialization goes here.
 * [4] Your update function goes here.
 *
 * Learn more about scripting: <%ManualUrl%>scripting/
 * Learn more about CCClass: <%ManualUrl%>scripting/ccclass.html
 * Learn more about life-cycle callbacks: <%ManualUrl%>scripting/life-cycle-callbacks.html
 */

  

二 粘貼修改ts文件

粘貼ts到.creator\asset-template\typescript (沒有則新建文件夾)

修改復制粘貼的ts文件名為NewTS,內容修改如下:

import { _decorator, Component, Node } from 'cc';
const { ccclass, property } = _decorator;

/**
 * @author chenkai <%DateTime%>
 */
@ccclass('<%Name%>')
export class <%Name%> extends Component {

    onLoad () {
        
    }
	
	start(){
	
	}
	
	onDestroy(){
		
	}
}

  

三 使用新建的模板

在cocos新建typescript,選擇剛剛粘貼修改的NewTS

 

 

新建的模板typescript如下

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM