//添加方法 public static void addEventLinstener(XLua.LuaTable scriptEnv, string priex = "do") { IEnumerator it = scriptEnv.GetKeys().GetEnumerator(); try { while (it.MoveNext()) { object f = scriptEnv.Get <object>(it.Current.ToString()); if (f != null && f.GetType() == typeof(XLua.LuaFunction)) { if (it.Current.ToString().StartsWith(priex)) { int name = int.Parse(it.Current.ToString().Substring(priex.Length)); unityAction3 unityFunction; scriptEnv.Get(it.Current.ToString(), out unityFunction); if (!isLinsteners(name)) { funcs.Add(name, unityFunction); } Logger.wanr(it.Current, "Lua 事件注册成功"); } } } } catch (Exception e) { Logger.wanr("Lua事件注册时出错"); Logger.wanr(e.Message); } }
public static void addLuaEventListener(XLua.LuaTable scriptEnv, string priex = "do") { IEnumerator it = scriptEnv.GetKeys().GetEnumerator(); try { while (it.MoveNext()) { object f = scriptEnv.Get <object>(it.Current.ToString()); if (f != null && f.GetType() == typeof(XLua.LuaFunction)) { if (it.Current.ToString().StartsWith(priex)) { int name = int.Parse(it.Current.ToString().Substring(priex.Length)); Node node = new Node(); node.parent = null; node.method = null; //unityAction3 unityFunction; //scriptEnv.Get(it.Current.ToString(), out node.action); node.action = scriptEnv.Get <XLua.LuaFunction>(it.Current.ToString()); if (!dict.ContainsKey(name)) { dict.Add(name, node); Logger.wanr(it.Current, "Lua 事件注册成功"); } else { Logger.wanr("Lua方法注册 失败: " + name); } } } } } catch (Exception e) { Logger.wanr("Lua事件注册时出错"); Logger.wanr(e.Message); } }
protected override string uiFormName() { #if HOTFIX_ENABLE return(scriptEnv.Get <string>("uiFormName")); #else return(null); #endif }
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(); } }
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 }
public static void Init() { XLua.LuaTable luaEnv = LogicSystem.Inst.m_luaScript; NetManager_OnRecv = luaEnv.Get <Action <int, int, Roma.LusuoStream> >("NetManager_OnRecv"); OpenLoading = luaEnv.Get <Action <bool> >("OpenLoading"); }