1.UIManager函数定义
bool isGameUIManager;
UIPanelType currentGamePanel;
2.建立字典Dictionary<UIPanelType,BasePanel> UIPanelDict;
构造UIManager时,实例化UIPanelDict=new Dictionary<UIPanelType,BasePanel>();
3.当切换菜单场景和游戏场景时,需要清空字典
ClearDict(){
foreach(var item in UIPanelDict)
{
item.Value.Dispose();}
UIPanelDict.Clear();
}
4.创建GameUIManager和MainUIManager函数,
public void MainUIManager(){
isGameUIManager=false;
if(UIPanelDict.Count!=0){
ClearDict();}
UIPanelDict.Add(UIPanelType.MainPanel,newMainPanel("Panel_Main",UIPanelType.MainPanel,this));
UIPanelDict.Add(UIPanelType.GamePanel,new GamePanel("Panel_Game",UIPanelType.GamePanel,this));
UIPanelDict.Add(UIPanelType.HelpPanel,new HelpPanel("Panel_Help",UIPanelType.HelpPanel,this));
UIPanelDict.Add(UIPanelType.SetPanel,new SetPanel("Panel_Set",UIPanelType.SetPanel,this));
UIPanelDict[UIPanelType.MainPanel].Show();
}
5.GameManager构建UImanager时调用MainUIManager。