protected override void OnInit(object userData) { base.OnInit(userData); luaEnv = LuaManager.luaEnv; //此处要从LuaManager上获取 全局只有一个 scriptEnv = luaEnv.NewTable(); LuaTable meta = luaEnv.NewTable(); meta.Set("__index", luaEnv.Global); scriptEnv.SetMetaTable(meta); meta.Dispose(); string prefabName = name; if (prefabName.Contains("(Clone)")) { prefabName = prefabName.Split(new string[] { "(Clone)" }, StringSplitOptions.RemoveEmptyEntries)[0] + "View"; } onInit = scriptEnv.GetInPath <OnInitHandler>(prefabName + ".OnInit"); onOpen = scriptEnv.GetInPath <OnOpenHandler>(prefabName + ".OnOpen"); onClose = scriptEnv.GetInPath <OnCloseHandler>(prefabName + ".OnClose"); onBeforDestroy = scriptEnv.GetInPath <OnBeforDestroyHandler>(prefabName + ".OnBeforDestroy"); scriptEnv.Set("self", this); if (onInit != null) { onInit(userData); } }
protected override void OnBeforDestroy() { base.OnBeforDestroy(); //备注 调用销毁的话,经常会造成Unity崩溃 if (onBeforDestroy != null) { onBeforDestroy(); } onInit = null; onOpen = null; onClose = null; onBeforDestroy = null; }
protected override void OnBeforDestroy() { base.OnBeforDestroy(); if (onBeforDestroy != null) { onBeforDestroy(); } onInit = null; onOpen = null; onClose = null; onBeforDestroy = null; int len = m_LuaComs.Length; for (int i = 0; i < len; i++) { LuaCom com = m_LuaComs[i]; com.Trans = null; com = null; } //卸载图片资源 // int len = m_LuaComs.Length; // for (int i = 0; i < len; i++) // { // LuaCom com = m_LuaComs[i]; // // switch (com.Type) // { // case LuaComType.Button: // case LuaComType.Image: // case LuaComType.YouYouImage: // { // Image img = com.Trans.GetComponent<Image>(); // img.sprite = null; // } // break; // case LuaComType.RawImage: // { // RawImage img = com.Trans.GetComponent<RawImage>(); // img.texture = null; // } // break; // } // // com.Trans = null; // com = null; // } }