势力部分缓存点击界面切换
初始化界面,指定物体及脚本,注册事件
public override void InitializeUI()
{
_spui = new SPUI_Faction();
_spui.BaseInit(base.gameObject, ILRT.Instance);
base.baseSpui = _spui;
UIEventListener.Get(_spui.BT_Close).onClick += ClickClose;
UIEventListener.Get(_spui.BT_Home).onClick += OnClickHome;//大厅
UIEventListener.Get(_spui.BT_Power).onClick += OnClickPower;//权势
UIEventListener.Get(_spui.BT_Base).onClick += OnClickBase;//基地
UIEventListener.Get(_spui.BT_Msg).onClick += OnClickMsg;//快报
UIEventListener.Get(_spui.BT_Activity).onClick += OnClickActivity;//活动
Test();
_spui.BT_Home.GetComponent<UIEventListener>().onClick(_spui.BT_Home);
}
点击权势
void OnClickPower(GameObject go)
{
CloseLastPanel();
UI_Logic logic = GetSubUI<UI_FactionPower>();
//((UI_HeroSkill)logic).SetData(hero);
}
隐藏所有同类
void CloseLastPanel()
{
if (_lastPanel != null)
_lastPanel.Hide();
}
打开点击的子界面
public T GetSubUI<T>() where T : UI_Logic
{
UI_Logic logic;
if (tempPanlList.TryGetValue(typeof(T).Name, out logic))
{
logic.Hide(false);
}
else
{
Globals.MUIManager.AddUI<T>(delegate (T uipage)
{
tempPanlList[typeof(T).Name] = uipage;
uipage.transform.parent = this.transform.GetChild(0);
logic = uipage;
});
}
_lastPanel = logic;
return (T)logic;
}
管理子界面的方法
UI_Logic _lastPanel;//缓存当前活动模块
Dictionary<string, UI_Logic> tempPanlList = new Dictionary<string, UI_Logic>();//所有加载过的活动模块
public T HasSubUI<T>() where T : UI_Logic
{
UI_Logic logic;
if (tempPanlList.TryGetValue(typeof(T).Name, out logic))
{
return (T)logic;
}
else
{
return null;
}
}