using System.Collections; using System.Collections.Generic; using UnityEngine; public class UIManager : SingleTon { private Dictionary uiDic = new Dictionary(); 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(); } 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()); } 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); } } }