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");
            onBeforeDestroy = scriptEnv.GetInPath <OnBeforeDestroyHandler>(prefabName + ".OnBeforeDestroy");

            scriptEnv.Set("self", this);
            if (onInit != null)
            {
                onInit(transform, userData);
            }
        }
        protected override void OnBeforeDestroy()
        {
            base.OnBeforeDestroy();
            if (onBeforeDestroy != null)
            {
                onBeforeDestroy();
            }
            onInit          = null;
            onOpen          = null;
            onClose         = null;
            onBeforeDestroy = null;

            //卸载图片资源
            int len = m_LuaComs.Length;

            for (int i = 0; i < len; i++)
            {
                LuaCom com = m_LuaComs[i];

                switch (com.Type)
                {
                case LuaComponentType.Button:
                case LuaComponentType.Image:
                case LuaComponentType.YouYouImage:
                {
                    Image ima = com.Trans.GetComponent <Image>();
                    ima.sprite = null;
                }
                break;

                case LuaComponentType.RawImage:
                {
                    RawImage ima = com.Trans.GetComponent <RawImage>();
                    ima.texture = null;
                }
                break;
                }
                com.Trans = null;
                com       = null;
            }
        }
Beispiel #3
0
        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");
            onBeforeDestroy = scriptEnv.GetInPath <OnBeforeDestroyHandler>(prefabName + ".OnBeforeDestroy");

            scriptEnv.Set("self", this);
            //LuaTable t = LuaManager.ReturnNewTable("UI_TaskView");
            //Debug.Log(t == null);
            //t.Set("name", this.gameObject.name);

            //LuaTable model = luaEnv.Global.GetInPath<LuaTable>("UI_TaskView");
            //LuaTable t = luaEnv.NewTable();
            //t.SetMetaTable(model);
            ////model.Dispose();
            //t.Set("name", this.gameObject.name);


            LuaTable tmodel = luaEnv.Global.GetInPath <LuaTable>(prefabName);

            tmodel.Set("__index", tmodel);

            t = luaEnv.NewTable();
            t.SetMetaTable(tmodel);

            t.Set("name", this.gameObject.name);

            ta = t.GetInPath <TableFunc>("PrintName");
            ta(t);

            //ta = t.GetInPath<TableFunc>("UI_TaskView" + ".PrintName");
            //Debug.Log(ta == null);
            //if (ta == null)
            //{
            //    onClose = t.GetInPath<OnCloseHandler>("UI_TaskView" + ".Pme");
            //    Debug.Log("onClose");
            //    Debug.Log(onClose == null);
            //    OnClose();
            //}
            //ta(t);


            if (onInit != null)
            {
                onInit(transform, userData);
            }
        }