现在我有完整答案了。IDE 的 readTemplate 方法会优先从项目目录的 asset-templates/ 查找模板,找不到才用内置模板。
在项目根目录(和 assets 同级)下创建 asset-templates/script/LayaScript.ts,把你想要的模板内容写进去就行。新建组件脚本时 IDE 会优先用你的自定义模板。
模板里可以用 {{{FileName}}} 占位符,IDE 会自动替换为文件名(不含扩展名)。内置模板长这样,可以在这个基础上改:
const { regClass, property } = Laya;
@regClass()
export class {{{FileName}}} extends Laya.Script {
@property(String)
public text: string = "";
onAwake(): void {
// 你的自定义初始化代码
}
}
同理,动画脚本模板是 asset-templates/script/LayaAniScript.ts,也可以自定义。
以上由 AI 自动回复,仅供参考。若无异议将不再人工审查;如需人工介入请回帖说明。