using System.Collections; using System.Collections.Generic; using UnityEngine; namespace TON { public class UIManager : SingletonBase { public VariableJoystick joystick; // Joystick 컴포넌트를 참조 public static T Show(UIList uiName) where T : UIBase { var targetUI = Singleton.GetUI(uiName); if (targetUI == null) { return null; } targetUI.Show(); return targetUI; } public static T Hide(UIList uiName) where T : UIBase { var targetUI = Singleton.GetUI(uiName); if (targetUI == null) { return null; } targetUI.Hide(); return targetUI; } private Dictionary panels = new Dictionary(); private Dictionary popups = new Dictionary(); private Transform panelRoot; private Transform popupRoot; private const string UI_PATH = "UI/Prefabs/"; public void Initalize() { if (panelRoot == null) { GameObject panelGo = new GameObject("Panel Root"); panelRoot = panelGo.transform; panelRoot.SetParent(transform); } if (popupRoot == null) { GameObject popupGo = new GameObject("Popup Root"); popupRoot = popupGo.transform; popupRoot.SetParent(transform); } for (int i = (int)UIList.PANEL_START + 1; i < (int)UIList.PANEL_END; i++) { panels.Add((UIList)i, null); } for (int i = (int)UIList.POPUP_START + 1; i < (int)UIList.POPUP_END; i++) { popups.Add((UIList)i, null); } } public T GetUI(UIList uiName, bool isReload = false) where T : UIBase { Dictionary container = null; if (uiName > UIList.PANEL_START && uiName < UIList.PANEL_END) { container = panels; } else { container = popups; } if (!container.ContainsKey(uiName)) { return null; } if (isReload && container[uiName]) { Destroy(container[uiName].gameObject); container[uiName] = null; } if (!container[uiName]) { string path = UI_PATH + $"UI.{uiName}"; T result = Resources.Load(path) as T; if (result) { container[uiName] = Instantiate(result, container == panels ? panelRoot : popupRoot); container[uiName].gameObject.SetActive(false); } } return container[uiName] as T; } } }