using Module.Log; using UnityEngine; public class UIControllerBase : MonoBehaviour { private static T _Instance; public GameObject[] childWindows; // 不确定窗口是否存在时需要判空 public static T Instance() { return _Instance; } public static void SetInstance(T instance) { _Instance = instance; } private void Awake() { Init(); } protected virtual void Init() { LogModule.DebugLog("Base Init"); //HotFix(); } // 如果覆盖了OnDestroy需要将_Instance置空,防止资源无法释放 protected virtual void OnDestroy() { Release(); } private void Release() { _Instance = default(T); } public void SwitchWindow(int index) { if (null == childWindows) { LogModule.WarningLog("child window is not set"); return; } if (index >= childWindows.Length) { LogModule.WarningLog("child window index out range :" + index + " " + childWindows.Length); return; } for (var i = 0; i < childWindows.Length; i++) childWindows[i].SetActive(i == index); } //#region hotfix ////global //public static LuaEnv luaEnv = new LuaEnv(); //public TextAsset _LuaScript; //private LuaTable scriptEnv; //public void HotFix() //{ // if (_LuaScript == null) // return; // scriptEnv = luaEnv.NewTable(); // LuaTable meta = luaEnv.NewTable(); // meta.Set("__index", luaEnv.Global); // scriptEnv.SetMetaTable(meta); // meta.Dispose(); // scriptEnv.Set("self", this); // luaEnv.DoString(_LuaScript.text, "LuaBehaviour", scriptEnv); // Action luaHotFix = scriptEnv.Get("hotfix"); // if (luaHotFix != null) // { // luaHotFix(); // } //} //public void ShowOtherUI(UIPathData pathData) //{ // UIManager.ShowUI(pathData); //} //public void CloseUI(UIPathData pathData) //{ // UIManager.CloseUI(pathData); //} //#endregion }