| 
									
										
										
										
											2022-01-26 07:46:33 +00:00
										 |  |  |  | using System; | 
					
						
							|  |  |  |  | using System.Collections; | 
					
						
							|  |  |  |  | using System.Collections.Generic; | 
					
						
							|  |  |  |  | using UnityEngine; | 
					
						
							|  |  |  |  | using UnityEngine.EventSystems; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | public class UIManager : S_MonoSingleton<UIManager> | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     public bool IsUICovered | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         get | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             return mUIList.Count > 0; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     public Canvas UICanvas | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         get | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             if (mUICanvas == null) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 mUICanvas = GetComponent<Canvas>(); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             return mUICanvas; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     public Camera UICamera | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         get | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             if (mUICamera == null) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 mUICamera = UICanvas.worldCamera; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             return mUICamera; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     private Canvas mUICanvas; | 
					
						
							|  |  |  |  |     private Camera mUICamera; | 
					
						
							|  |  |  |  |     private Dictionary<Type, BasePanel> mUIDic = new Dictionary<Type, BasePanel>(); | 
					
						
							|  |  |  |  |     private List<BasePanel> mUIList = new List<BasePanel>(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     public T OpenUI<T>() where T : BasePanel | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         T tUI = GetUI<T>(); | 
					
						
							| 
									
										
										
										
											2022-02-10 10:17:22 +00:00
										 |  |  |  |         tUI.gameObject.SetActive(true); | 
					
						
							|  |  |  |  |         tUI.OnOpen(); | 
					
						
							| 
									
										
										
										
											2022-01-26 07:46:33 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |         if (mUIList.Contains(tUI)) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             mUIList.Remove(tUI); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         if (mUIList.Count > 0) | 
					
						
							|  |  |  |  |         { | 
					
						
							| 
									
										
										
										
											2022-02-10 10:17:22 +00:00
										 |  |  |  |             mUIList[mUIList.Count - 1].OnFocus(false); | 
					
						
							| 
									
										
										
										
											2022-01-26 07:46:33 +00:00
										 |  |  |  |         } | 
					
						
							|  |  |  |  |         mUIList.Add(tUI); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         return tUI; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     public T CloseUI<T>() where T : BasePanel | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         T tUI = GetUI<T>(); | 
					
						
							| 
									
										
										
										
											2022-02-14 09:14:06 +00:00
										 |  |  |  |         CloseUI(tUI); | 
					
						
							| 
									
										
										
										
											2022-01-26 07:46:33 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |         return tUI; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-10 10:17:22 +00:00
										 |  |  |  |     public void CloseUI(BasePanel pBasePanel) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         pBasePanel.gameObject.SetActive(false); | 
					
						
							| 
									
										
										
										
											2022-02-14 09:14:06 +00:00
										 |  |  |  |         pBasePanel.OnClose(); | 
					
						
							| 
									
										
										
										
											2022-02-10 10:17:22 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |         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); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-26 07:46:33 +00:00
										 |  |  |  |     public T GetUI<T>() where T : BasePanel | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         T tUI = null; | 
					
						
							|  |  |  |  |         if (!mUIDic.ContainsKey(typeof(T))) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             mUIDic[typeof(T)] = GetComponentInChildren<T>(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<RaycastResult> results = new List<RaycastResult>(); | 
					
						
							|  |  |  |  |             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<GameObject> GetChildGobList(Transform pParent) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         List<GameObject> tList = new List<GameObject>(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         for (int i = 0; i < pParent.childCount; i++) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             tList.Add(pParent.GetChild(i).gameObject); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         return tList; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     public static List<T> GetChildList<T>(Transform pParent) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         List<T> tList = new List<T>(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         for (int i = 0; i < pParent.childCount; i++) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             tList.Add(pParent.GetChild(i).GetComponent<T>()); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         return tList; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | } |