Files
JJBB/Assets/Project/Script/GUI/UIControllerBase.cs
2024-08-23 15:49:34 +08:00

101 lines
2.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Module.Log;
using UnityEngine;
public class UIControllerBase<T> : 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<Action>("hotfix");
// if (luaHotFix != null)
// {
// luaHotFix();
// }
//}
//public void ShowOtherUI(UIPathData pathData)
//{
// UIManager.ShowUI(pathData);
//}
//public void CloseUI(UIPathData pathData)
//{
// UIManager.CloseUI(pathData);
//}
//#endregion
}