Exemple #1
0
        protected override void OnRelease()
        {
            if (luaOnRelease != null)
            {
                luaOnRelease();
            }
#if HOTFIX_ENABLE
            scriptEnv.Dispose();
#endif
        }
Exemple #2
0
        public void LoadLuaString(bool isAssetBundle, string dirType, string scriptName, string scriptPath)
        {
#if HOTFIX_ENABLE
            scriptEnv = UIManager.luaenv.NewTable();
            XLua.LuaTable meta = UIManager.luaenv.NewTable();
            meta.Set("__index", UIManager.luaenv.Global);
            scriptEnv.SetMetaTable(meta);
            meta.Dispose();
            scriptEnv.Set("self", this);

            if (dirType == "Resources")
            {
                TextAsset luaStr = Resources.Load <TextAsset>(scriptPath);
                if (luaStr != null)
                {
                    UIManager.luaenv.DoString(luaStr.text, "LuaUIBehaviour", scriptEnv);
                }
                else
                {
                    Debug.Log(scriptPath + "is null!");
                }
            }
            else if (dirType == "streamingAssetsPath")
            {
#if UNITY_ANDROID && !UNITY_EDITOR
                string str = UIFactory.GetAndoidStreamingAssetLuaScripts(scriptName);
                if (!string.IsNullOrEmpty(str))
                {
                    UIManager.luaenv.DoString(str, "LuaUIBehaviour", scriptEnv);
                }
                else
                {
                    Debug.Log(scriptPath + "is null!");
                }
#else
                LoadLuaScript(isAssetBundle, dirType, scriptName, scriptPath);
#endif
            }
            else
            {
                LoadLuaScript(isAssetBundle, dirType, scriptName, scriptPath);
            }

            scriptEnv.Get("uiFormType", out _luaUiFormType);
            scriptEnv.Get("OnInit", out luaOnInit);
            scriptEnv.Get("OnExcute", out luaOnExcute);
            scriptEnv.Get("OnDisplay", out luaOnDisplay);
            scriptEnv.Get("OnHide", out luaOnHide);
            scriptEnv.Get("OnReDisplay", out luaOnReDisplay);
            scriptEnv.Get("OnFreese", out luaOnFreese);
            scriptEnv.Get("OnRelease", out luaOnRelease);
#endif
        }
Exemple #3
0
        static void GenProtocol()
        {
            LuaManager luaMgr           = new LuaManager();
            Action <string, string> gen = null;

            XLua.LuaTable protocol = null;
            try
            {
                luaMgr.Init();
                luaMgr.AddSearchPath(EditorConst.EditorDir);
                luaMgr.AddSearchPath(EditorConst.ScriptDir);
                protocol = luaMgr.GetTable("Protocol");

                List <string> files = new List <string>(Directory.GetFiles(c2s_dir));
                files.Add(notice_file);
                StringBuilder des = new StringBuilder();
                for (int i = 0; i < files.Count; i++)
                {
                    string content = File.ReadAllText(files[i]);
                    des.AppendFormat("{0}\n", content);
                }

                string rawProto  = File.ReadAllText(protoc_file);
                string desString = string.Format("return [[\n{0}]]", des.ToString());
                gen = protocol.Get <Action <string, string> >("GenProtocol");
                gen(desString, rawProto);
                gen = null;

                string messageString = protocol.Get <Func <string> >("GetMessageString")();
                string protoString   = protocol.Get <Func <string> >("GetProtoString")();
                string dir           = EditorConst.ScriptDir + "/Protocol/";
                File.WriteAllText(dir + "Descriptor.lua", desString);
                File.WriteAllText(dir + "Protocol.lua", protoString);
                File.WriteAllText(dir + "Message.lua", messageString);
            }
            catch (Exception e)
            {
                Debug.LogErrorFormat("{0}\n{1}", e.Message, e.StackTrace);
            }
            finally
            {
                protocol.Dispose();
                protocol = null;
                luaMgr.Dispose();
            }
        }