public void Dispose(bool destoryService = true) { if (L == null) { return; } if (_DispatchEvent != null) { _DispatchEvent("UNITY_OnApplicationQuit"); } _Sync = null; _RegisterEventListener = null; _RemoveEventListener = null; _DispatchEvent = null; _StartLuaCoroutineDelegate = null; #if UNITY_EDITOR LL = L; #else Debug.LogFormat("GC"); L.GC(); System.GC.Collect(); L.Dispose(); L = null; #endif }
public void Dispose(bool destoryService = true) { if (L == null) { return; } if (_DispatchEvent != null) { _DispatchEvent("UNITY_OnApplicationQuit"); } _RegisterEventListener = null; _RemoveEventListener = null; _DispatchEvent = null;; _StartLuaCoroutineDelegate = null; //if (destoryService) //{ // IService[] services = gameObject.GetComponents<IService>(); // for (int i = 0; i < services.Length; i++) // { // DestroyImmediate(services[i] as MonoBehaviour); // } //} L.GC(); System.GC.Collect(); L.Dispose(); L = null; }
void Awake() { var p = Application.backgroundLoadingPriority; Application.backgroundLoadingPriority = ThreadPriority.High; if (instance != null) { DestroyImmediate(gameObject); return; } instance = this; DontDestroyOnLoad(this.gameObject); L = new LuaEnv(); L.AddLoader(FileUtils.Load); LuaBehaviour.CleanStatlessFile(); L.Global.Set <string, XLua.LuaDLL.lua_CSFunction>("WARNING_LOG", CustomSettings.PrintWarning); L.Global.Set <string, XLua.LuaDLL.lua_CSFunction>("ERROR_LOG", CustomSettings.PrintError); L.Global.Set <string, XLua.LuaDLL.lua_CSFunction>("BATTLE_LOG", CustomSettings.BATTLE_LOG); L.Global.Set <string, XLua.LuaDLL.lua_CSFunction> ("loadstring", CustomSettings.LoadString); IService[] services = gameObject.GetComponents <IService>(); for (int i = 0; i < services.Length; i++) { services[i].Register(L); } //L.DoString("require('LuaDebug')('localhost',7003)"); L.DoString("require 'utils.init'"); _RegisterEventListener = L.Global.Get <System.Action <object> >("RegisterEventListener"); _RemoveEventListener = L.Global.Get <System.Action <object> >("RemoveEventListener"); _DispatchEvent = L.Global.Get <DispatchEventDelegate>("DispatchEvent"); _StartLuaCoroutineDelegate = L.Global.Get <StartLuaCoroutineDelegate>("StartCoroutine"); _Sync = L.Global.Get <SyncDelegate>("Sync"); }