private void createLuaFieldByTrans(Transform trans, List <string> classDesc) { BTLog.Debug("createLuaFieldByTrans:{0}", trans.name); var numChildren = trans.childCount; var nameList = new List <string>(); for (var i = 0; i < numChildren; i++) { var child = trans.GetChild(i); var childName = child.name; if (nameList.Contains(childName)) { throw new Exception(string.Format("组件命名重复:{0}", childName)); } nameList.Add(childName); var suffix = Utils.GetSuffixOfGoName(childName); // 如果不是合法后缀,则直接进入下一级,继续生成子go的fields if (!Utils.IsValidSuffix(suffix)) { createLuaFieldByTrans(child, classDesc); continue; } classDesc.Insert(classDesc.Count - 1, string.Format("---@field {0} {1}", childName, Utils.GetTypeNameByComponentSuffix(suffix, child))); // _Doc不用对其子go生成field if (suffix != "_Doc") { createLuaFieldByTrans(child, classDesc); } } }
private void Awake() { if (ins == null) { ins = this; } CreateUIStage(); luaState = new LuaState(); OpenLibs(); luaState.LuaSetTop(0); Bind(); LoadLuaFiles(); #if UNITY_EDITOR && !LOADFROM_BUNDLE BTLog.Debug("open HotFixLua"); var hot = this.gameObject.AddComponent <HotFixLua>(); hot.LuaPath = "/Lua/"; #endif }
private void BindFieldsOnTrans(Transform trans, int topIdx) { BTLog.Debug("BindFieldsOnTrans trans:{0}", trans.name); var luaState = MainGame.Ins.LuaState; var numChildren = trans.childCount; for (int i = 0; i < numChildren; i++) { var child = trans.GetChild(i); var childName = child.name; if (childName == "") { continue; } var suffix = Utils.GetSuffixOfGoName(childName); // 如果不是合法后缀,则直接进入下一级,检测子go有没有需要绑定的 if (!Utils.IsValidSuffix(suffix)) { BindFieldsOnTrans(child, topIdx); continue; } // 对Doc进行特殊处理,这个不能直接绑定cs组件,需要创建一个lua对象,然后进行绑定 if (suffix == "_Doc") { var childDoc = child.GetComponent <DocumentClass>(); childDoc.CreatePrefabAndBindLuaClass(); var childContextId = childDoc.GetContextId(); MainGame.Ins.GetPrefabLua(childContextId); luaState.LuaSetField(topIdx, childName); } else { BindFieldsOnTrans(child, topIdx); var T = Utils.GetTypeByComponentSuffix(suffix); if (T == null) { continue; } luaState.PushVariant(child.GetComponent(T)); luaState.LuaSetField(topIdx, childName); } BTLog.Debug("bind {0}. name:{1} childName:{2}", suffix, trans.name, childName); } }