public void Destroy() { if (luaState != null) { if (UpdateEvent != null) { UpdateEvent.Dispose(); UpdateEvent = null; } if (LateUpdateEvent != null) { LateUpdateEvent.Dispose(); LateUpdateEvent = null; } if (FixedUpdateEvent != null) { FixedUpdateEvent.Dispose(); FixedUpdateEvent = null; } luaState = null; } }
LuaEvent GetEvent(string name) { LuaTable table = luaState.GetTable(name); LuaEvent e = new LuaEvent(table); table.Dispose(); table = null; return e; }
void Start () { luaState.Start(); luaState.DoFile("Main.lua"); updateFunc = luaState.GetFunction("Update"); lateUpdateFunc = luaState.GetFunction("LateUpdate"); fixedUpdateFunc = luaState.GetFunction("FixedUpdate"); levelLoaded = luaState.GetFunction("OnLevelWasLoaded"); LuaFunction main = luaState.GetFunction("Main"); main.Call(); main.Dispose(); main = null; UpdateEvent = GetEvent("UpdateBeat"); LateUpdateEvent = GetEvent("LateUpdateBeat"); FixedUpdateEvent = GetEvent("FixedUpdateBeat"); }
public void InitStart() { InitLuaPath(); InitLuaBundle(); this.lua.Start(); //启动LUAVM lua.DoFile("Main.lua"); updateFunc = lua.GetFunction("Update"); lateUpdateFunc = lua.GetFunction("LateUpdate"); fixedUpdateFunc = lua.GetFunction("FixedUpdate"); LuaFunction main = lua.GetFunction("Main"); main.Call(); main.Dispose(); main = null; UpdateEvent = GetEvent("UpdateBeat"); LateUpdateEvent = GetEvent("LateUpdateBeat"); FixedUpdateEvent = GetEvent("FixedUpdateBeat"); }
public void Close() { SafeRelease(ref updateFunc); SafeRelease(ref lateUpdateFunc); SafeRelease(ref fixedUpdateFunc); if (UpdateEvent != null) { UpdateEvent.Dispose(); UpdateEvent = null; } if (LateUpdateEvent != null) { LateUpdateEvent.Dispose(); LateUpdateEvent = null; } if (FixedUpdateEvent != null) { FixedUpdateEvent.Dispose(); FixedUpdateEvent = null; } lua.Dispose(); lua = null; loader = null; }
void OnApplicationQuit() { if (luaState != null) { SafeRelease(ref updateFunc); SafeRelease(ref lateUpdateFunc); SafeRelease(ref fixedUpdateFunc); SafeRelease(ref levelLoaded); if (UpdateEvent != null) { UpdateEvent.Dispose(); UpdateEvent = null; } if (LateUpdateEvent != null) { LateUpdateEvent.Dispose(); LateUpdateEvent = null; } if (FixedUpdateEvent != null) { FixedUpdateEvent.Dispose(); FixedUpdateEvent = null; } luaState.Dispose(); luaState = null; Instance = null; } }
void SafeRelease(ref LuaEvent luaEvent) { if (luaEvent != null) { luaEvent.Dispose(); luaEvent = null; } }
void Start() { try { UpdateEvent = GetEvent("UpdateBeat"); LateUpdateEvent = GetEvent("LateUpdateBeat"); FixedUpdateEvent = GetEvent("FixedUpdateBeat"); } catch (Exception e) { Destroy(this); throw e; } }
LuaEvent GetEvent(string name) { LuaTable table = luaState.GetTable(name); if (table == null) { throw new LuaException(string.Format("Lua table {0} not exists", name)); } LuaEvent e = new LuaEvent(table); table.Dispose(); table = null; return e; }