在游戏开发中,咱们的开发流程通常是node
我开发了款半自动代码生成器工具主要是解决第2步的问题;之因此称之为半自动,由于我以为全自动代码生成器应该作到两点:代码生成(第2步)+自动绑定(第3步)。自动绑定须要改动预制体文件,因为全部人的使用方式不尽相同,出现的问题会比较多,我喜欢相对灵活,约束比较少的方式,因此我采用了拖拽设置和代码设置相结合的方式解决自动绑定的问题。微信
导出与预制体同名的类文件mvc
声明属性
框架
若是属性是无效值进行赋值
函数
若是属性是按钮,进行函数监听,并生成监听函数
工具
将生成的类导出到指定目录测试
支持导出指定预制体文件或者目录,自动实别目录的子目录。ui
支持导出Creator 和 Laya 的预制体this
使用TAG标记是否导出指定名称的属性,带有TAG标记符号的节点才会导出,我TAG是$。若是TAG是无效字符,那么会导出全部名称有效的节点。
code
creator导出的属性名称后面带有类型,button带有sprite会同时输出。
creator_export:creator文件导出目录,这个目录工具会建立而且能够放到其余地方。
creator_prefabs: creator文件输入目录,通常会设置为项目的预制体文件夹。放到这里只是测试使用。
laya_export 和 laya_prefabs :同 creator文件夹。
creator_build.bat: window下的运行脚本,实际上就是直行node 并传递两个参数。若是是mac用户能够自行写一个sh脚本。
creator_prefab.js: creator文件导出的核心代码。
creator_template.txt: creator导出文件的模板文件,理论上就是字符替换。
file_util.js : 文件辅助类
laya_build.bat,laya_prefab.js,laya_template.txt: 同creator文件。
import BaseView from "../../../cfw/mvc/BaseView"; const { ccclass, property } = cc._decorator; @ccclass export default class LoginView extends BaseView { @property({type: cc.Sprite, displayName: "logointro$Sprite"}) logointro$Sprite: cc.Sprite = null; @property({type: cc.Sprite, displayName: "btn_buy_big$Sprite"}) btn_buy_big$Sprite: cc.Sprite = null; @property({type: cc.Button, displayName: "btn_buy_big$Button"}) btn_buy_big$Button: cc.Button = null; onLoad() { if(!this.logointro$Sprite){this.logointro$Sprite = this.findChild("logointro$").getComponent(cc.Sprite)} if(!this.btn_buy_big$Sprite){this.btn_buy_big$Sprite = this.findChild("btn_buy_big$").getComponent(cc.Sprite)} if(!this.btn_buy_big$Button){this.btn_buy_big$Button = this.findChild("btn_buy_big$").getComponent(cc.Button)} this.registerButtonByNode(this.btn_buy_big$Button,this.onbtn_buy_big$ButtonClick) } onbtn_buy_big$ButtonClick(){ } onDestroy(){ } }
import BaseView from "../../../cfw/mvc/BaseView"; export default class TestView extends BaseView { /** @prop {name:normal, tips:"normal", type:Node, default:null}*/ public normal: Laya.Button = null; /** @prop {name:double, tips:"double", type:Node, default:null}*/ public double: Laya.Button = null; constructor() { super(); } onAwake() { super.onAwake() if(!this.normal){this.normal = this.findChild("normal")} this.registerButtonByNode(this.normal,this.onnormalClick) if(!this.double){this.double = this.findChild("double")} this.registerButtonByNode(this.double,this.ondoubleClick) } onEnable(): void { } onDisable(): void { } onnormalClick(){ } ondoubleClick(){ } }
工具已上传到框架仓库中,有须要的自行拉取,如遇到问题能够微信找我沟通。
欢迎扫码关注公众号《微笑游戏》,浏览更多内容。