using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; public class UIManager : S_MonoSingleton { public bool IsUICovered { get { return mUIList.Count > 0; } } public Canvas UICanvas { get { if (mUICanvas == null) { mUICanvas = GetComponent(); } return mUICanvas; } } public Camera UICamera { get { if (mUICamera == null) { mUICamera = UICanvas.worldCamera; } return mUICamera; } } private Canvas mUICanvas; private Camera mUICamera; private Dictionary mUIDic = new Dictionary(); private List mUIList = new List(); public T OpenUI() where T : BasePanel { T tUI = GetUI(); tUI.gameObject.SetActive(true); tUI.OnOpen(); if (mUIList.Contains(tUI)) { mUIList.Remove(tUI); } if (mUIList.Count > 0) { mUIList[mUIList.Count - 1].OnFocus(false); } mUIList.Add(tUI); return tUI; } public T CloseUI() where T : BasePanel { T tUI = GetUI(); CloseUI(tUI); return tUI; } public void CloseUI(BasePanel pBasePanel) { pBasePanel.gameObject.SetActive(false); pBasePanel.OnClose(); int tIndex = mUIList.IndexOf(pBasePanel); if (tIndex == mUIList.Count - 1) { mUIList.Remove(pBasePanel); if (mUIList.Count > 0) { mUIList[mUIList.Count - 1].OnFocus(true); } } else { mUIList.Remove(pBasePanel); } } public T GetUI() where T : BasePanel { T tUI = null; if (!mUIDic.ContainsKey(typeof(T))) { mUIDic[typeof(T)] = GetComponentInChildren(true); } tUI = mUIDic[typeof(T)] as T; return tUI; } public void ShowTip(string pTip) { } public static bool IsTouchUI() { if (EventSystem.current != null) { PointerEventData eventData = new PointerEventData(EventSystem.current); eventData.position = Input.mousePosition; List results = new List(); EventSystem.current.RaycastAll(eventData, results); if (results == null || results.Count == 0) { return false; } return results.Count > 0 && results[0].gameObject.layer == 5; } return false; } public static List GetChildGobList(Transform pParent) { List tList = new List(); for (int i = 0; i < pParent.childCount; i++) { tList.Add(pParent.GetChild(i).gameObject); } return tList; } public static List GetChildList(Transform pParent) { List tList = new List(); for (int i = 0; i < pParent.childCount; i++) { tList.Add(pParent.GetChild(i).GetComponent()); } return tList; } }