93 lines
1.9 KiB
C#
93 lines
1.9 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class UIManager : SingleTon<UIManager>
|
|
{
|
|
private Dictionary<UIType, UIBase> uiDic = new Dictionary<UIType, UIBase>();
|
|
|
|
public GameData GameData { get; private set; }
|
|
|
|
public void Init()
|
|
{
|
|
GameData = DataManager.Instance.GetGameData();
|
|
}
|
|
|
|
public UIBase GetUIBase(UIType uIType)
|
|
{
|
|
if (uiDic.ContainsKey(uIType))
|
|
{
|
|
return uiDic[uIType].gameObject.GetComponent<UIBase>();
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public UIBase OpenUI(UIType uIType)
|
|
{
|
|
if (uiDic.ContainsKey(uIType))
|
|
{
|
|
uiDic[uIType]?.Open();
|
|
}
|
|
else
|
|
{
|
|
GameObject Prefab = (GameObject)Resources.Load("UIPrefabs/" + uIType.ToString());
|
|
var newUI = GameObject.Instantiate(Prefab, GameData.mainCanvas.transform);
|
|
uiDic.Add(uIType, newUI.GetComponent<UIBase>());
|
|
}
|
|
return uiDic[uIType];
|
|
}
|
|
|
|
public void CloseUI(UIType uIType)
|
|
{
|
|
if (uiDic.ContainsKey(uIType))
|
|
{
|
|
uiDic[uIType]?.Close();
|
|
}
|
|
}
|
|
|
|
public bool isShow(UIType uIType)
|
|
{
|
|
if (uiDic.ContainsKey(uIType))
|
|
{
|
|
return uiDic[uIType].gameObject.activeSelf;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public void ShowMainUI()
|
|
{
|
|
GameData.mainUI.Open();
|
|
}
|
|
public void CloseMainUI()
|
|
{
|
|
GameData.mainUI.Close();
|
|
|
|
}
|
|
|
|
public void CloseAllUI()
|
|
{
|
|
foreach (var ui in uiDic.Values)
|
|
{
|
|
ui.Close();
|
|
}
|
|
CloseMainUI();
|
|
}
|
|
|
|
public void ShowAllUI()
|
|
{
|
|
foreach (var ui in uiDic.Values)
|
|
{
|
|
ui.Open();
|
|
}
|
|
ShowMainUI();
|
|
}
|
|
|
|
public void DestoryUI(UIType uIType)
|
|
{
|
|
if (uiDic.ContainsKey(uIType))
|
|
{
|
|
uiDic[uIType].Destroy();
|
|
uiDic.Remove(uIType);
|
|
}
|
|
}
|
|
} |