/// <summary> /// Initialize instead of Awake and Start function.Initialize function called by lauMVC. /// </summary> public virtual void Initialize() { m_transform = this.transform; m_gameobject = m_transform.gameObject; m_panel = m_transform.Find("Panel"); ViewMaster.AddView(this); }
public void Init(string scriptName) { scriptEnv = LuaApplicationFacade.luaEnv.NewTable(); LuaTable meta = LuaApplicationFacade.luaEnv.NewTable(); meta.Set("__index", LuaApplicationFacade.luaEnv.Global); scriptEnv.SetMetaTable(meta); meta.Dispose(); // 加载lua script LuaApplicationFacade.luaEnv.DoString("require " + "'" + scriptName + "'", "LuaComponent", scriptEnv); scriptEnv.SetInPath <MonoBehaviour>(scriptName + ".self", this); if (null != this.transform.Find("Panel")) { scriptEnv.SetInPath <GameObject>(scriptName + ".panel", this.transform.Find("Panel").gameObject); } luaStart = scriptEnv.GetInPath <Action>(scriptName + ".start"); luaUpdate = scriptEnv.GetInPath <Action>(scriptName + ".update"); luaOnDestroy = scriptEnv.GetInPath <Action>(scriptName + ".ondestroy"); Action luaAwake = scriptEnv.GetInPath <Action>(scriptName + ".awake"); luaBaseView = new LuaBaseView(); luaBaseView.ViewName = LuaApplicationFacade.luaEnv.Global.GetInPath <string>(scriptName + ".ViewName"); if (string.IsNullOrEmpty(luaBaseView.ViewName)) { luaBaseView.ViewName = scriptName + "View"; LuaMVCDebug.DebugWarning(scriptName + "not contain a viewName property,Please add it. (View脚本未添加ViewName属性)"); } luaBaseView.Initialize = LuaApplicationFacade.luaEnv.Global.GetInPath <Action>(scriptName + ".Initialize"); luaBaseView.Open = LuaApplicationFacade.luaEnv.Global.GetInPath <Action>(scriptName + ".Open"); luaBaseView.Close = LuaApplicationFacade.luaEnv.Global.GetInPath <Action>(scriptName + ".Close"); if (null != luaAwake) { luaAwake(); //todo 可以在这个方法中将gameobject或者是transform赋值给lua侧,减少lua侧代码量 if (null != luaBaseView.Initialize) { luaBaseView.Initialize(); } } ViewMaster.AddView(luaBaseView); }