public LuaScreenBaseCreate(GameObject root) { if (root == null) { return; } if (root.name.EndsWith(UIConstEditor.Str_UISubScreenEndType)) { Debug.LogErrorFormat("命名以 {0} 结尾的物体请使用 {1} 生成!", UIConstEditor.Str_UIScreenEndType, UIConstEditor.Str_UISubScreenEndType); return; } if (root.name.EndsWith(UIConstEditor.Str_UIScreenEndType) == false) { Debug.LogErrorFormat("请选择命名以 {0} 结尾的物体!", UIConstEditor.Str_UIScreenEndType); return; } // 设置注释 SetAnnotation(Const.Str_Lua_UIAnnotation); // 类名 SetClassName(root.name); // 重写方法 string space = " "; List <string> loadSuccessBody = new List <string>(); loadSuccessBody.Add(space + "-- 注册UI监听"); loadSuccessBody.Add(string.Format("{0}self:{1}();", space, UIConstEditor.Str_UIMethod_RegisterUI)); loadSuccessBody.Add(space + "-- 注册事件监听"); loadSuccessBody.Add(string.Format("{0}self:{1}();", space, UIConstEditor.Str_UIMethod_RegisterFevent)); LuaMethodBase loadSuccess = new LuaMethodBase(); loadSuccess.SetMethodName(string.Format("{0}:{1}", ClassName, UIConstEditor.Str_UIMethod_OnLoadSuccess)) .SetReturnType(Const.Return_Void) .SetMethodBody(loadSuccessBody) .SetAnnotation("UI资源加载完成回调,UI关闭前再调用OpenUI不会再调用"); AddMethod(loadSuccess); LuaMethodBase onInit = new LuaMethodBase(); onInit.SetMethodName(string.Format("{0}:{1}", ClassName, UIConstEditor.Str_UIMethod_OnInit)) .SetAnnotation("UI初始化,每次调用OpenUI都会执行"); AddMethod(onInit); LuaMethodBase dispose = new LuaMethodBase(); dispose.SetMethodName(string.Format("{0}:{1}", ClassName, UIConstEditor.Str_UIMethod_Dispose)) .SetAnnotation("UI销毁,可做事件注销"); AddMethod(dispose); LuaMethodBase onClose = new LuaMethodBase(); onClose.SetMethodName(string.Format("{0}:{1}", ClassName, UIConstEditor.Str_UIMethod_OnClose)) .SetAnnotation("UI关闭"); AddMethod(onClose); List <string> onClickMaskAreaBody = new List <string>(); onClickMaskAreaBody.Add(string.Format(" self:{0}();", UIConstEditor.Str_UIMethod_OnClose)); LuaMethodBase onClickMaskArea = new LuaMethodBase(); onClickMaskArea.SetMethodName(string.Format("{0}:{1}", ClassName, UIConstEditor.Str_UIMethod_OnClickMaskArea)) .SetMethodBody(onClickMaskAreaBody) .SetAnnotation("UI点击背景遮罩事件,默认执行OnClose方法关闭UI"); AddMethod(onClickMaskArea); LuaMethodBase registerUI = new LuaMethodBase(); registerUI.SetMethodName(string.Format("{0}:{1}", ClassName, UIConstEditor.Str_UIMethod_RegisterUI)) .SetAnnotation("UI事件注册"); AddMethod(registerUI); LuaMethodBase registerFevent = new LuaMethodBase(); registerFevent.SetMethodName(string.Format("{0}:{1}", ClassName, UIConstEditor.Str_UIMethod_RegisterFevent)) .SetAnnotation("消息事件注册"); AddMethod(registerFevent); SetLegal(true); }
public LuaSubScreenBaseCreate(GameObject root) { if (root == null) { return; } if (root.name.EndsWith(UIConstEditor.Str_UISubScreenEndType) == false) { Debug.LogErrorFormat("请选择命名以 {0} 结尾的物体!", UIConstEditor.Str_UISubScreenEndType); return; } string space = " "; // 设置注释 SetAnnotation(Const.Str_Lua_UIAnnotation); // 类名 SetClassName(root.name); // 重写方法 List <string> initBody = new List <string>(); initBody.Add(string.Format("{0}self:{1}();", space, UIConstEditor.Str_UIMethod_OnSpawn)); LuaMethodBase init = new LuaMethodBase(); init.SetMethodName(string.Format("{0}:{1}", ClassName, UIConstEditor.Str_UIMethod_Init)) .SetMethodBody(initBody) .SetAnnotation("初始化"); AddMethod(init); List <string> disposeBody = new List <string>(); disposeBody.Add(string.Format("{0}self:{1}();", space, UIConstEditor.Str_UIMethod_OnRelease)); LuaMethodBase dispose = new LuaMethodBase(); dispose.SetMethodName(string.Format("{0}:{1}", ClassName, UIConstEditor.Str_UIMethod_Dispose)) .SetMethodBody(disposeBody) .SetAnnotation("销毁"); AddMethod(dispose); List <string> onSpawnBody = new List <string>(); onSpawnBody.Add(space + "-- 注册UI监听"); onSpawnBody.Add(string.Format("{0}self:{1}();", space, UIConstEditor.Str_UIMethod_RegisterUI)); onSpawnBody.Add(space + "-- 注册事件监听"); onSpawnBody.Add(string.Format("{0}self:{1}();", space, UIConstEditor.Str_UIMethod_RegisterFevent)); LuaMethodBase onSpawn = new LuaMethodBase(); onSpawn.SetMethodName(string.Format("{0}:{1}", ClassName, UIConstEditor.Str_UIMethod_OnSpawn)) .SetMethodBody(onSpawnBody) .SetAnnotation("提取"); AddMethod(onSpawn); List <string> onReleaseBody = new List <string>(); onReleaseBody.Add(space + "-- 移除事件监听"); onReleaseBody.Add(string.Format("{0}self:{1}();", space, UIConstEditor.Str_UIMethod_UnRegisterFevent)); LuaMethodBase onRelease = new LuaMethodBase(); onRelease.SetMethodName(string.Format("{0}:{1}", ClassName, UIConstEditor.Str_UIMethod_OnRelease)) .SetMethodBody(onReleaseBody) .SetAnnotation("回收"); AddMethod(onRelease); MethodBase registerUI = new LuaMethodBase(); registerUI.SetMethodName(string.Format("{0}:{1}", ClassName, UIConstEditor.Str_UIMethod_RegisterUI)) .SetAnnotation("UI事件注册"); AddMethod(registerUI); LuaMethodBase registerFevent = new LuaMethodBase(); registerFevent.SetMethodName(string.Format("{0}:{1}", ClassName, UIConstEditor.Str_UIMethod_RegisterFevent)) .SetAnnotation("消息事件注册"); AddMethod(registerFevent); LuaMethodBase unRegisterFevent = new LuaMethodBase(); unRegisterFevent.SetMethodName(string.Format("{0}:{1}", ClassName, UIConstEditor.Str_UIMethod_UnRegisterFevent)) .SetAnnotation("消息事件取消注册"); AddMethod(unRegisterFevent); SetLegal(true); }