From 09bc892c7283df8757a07b646d5af21ddaa263d1 Mon Sep 17 00:00:00 2001
From: lcy <1459594991@qq.com>
Date: 星期四, 06 十一月 2025 18:22:34 +0800
Subject: [PATCH] 164 天子的考验-客户端

---
 Main/Manager/UIManager.cs |  218 ++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 161 insertions(+), 57 deletions(-)

diff --git a/Main/Manager/UIManager.cs b/Main/Manager/UIManager.cs
index 6ef3fd8..eed236b 100644
--- a/Main/Manager/UIManager.cs
+++ b/Main/Manager/UIManager.cs
@@ -30,8 +30,13 @@
     private Transform loadingTrans;
 
     // UI瀛楀吀锛屽瓨鍌ㄦ墍鏈夊凡鍔犺浇鐨刄I锛岄敭涓篣I鍚嶇О锛屽�间负UI瀹炰緥
-    private Dictionary<string, List<UIBase>> uiDict = new Dictionary<string, List<UIBase>>();
-    
+#if UNITY_EDITOR
+    public
+#else
+    private
+#endif 
+    Dictionary<string, List<UIBase>> uiDict = new Dictionary<string, List<UIBase>>();
+
     // 瀛樺偍鍏抽棴浣嗘湭閿�姣佺殑UI锛岄敭涓篣I鍚嶇О锛屽�间负UI瀹炰緥
     private Dictionary<string, List<UIBase>> closedUIDict = new Dictionary<string, List<UIBase>>();
 
@@ -45,7 +50,7 @@
     private int currentRound = 0;
     
     // 缂撳瓨灞傜骇瀵瑰簲鐨勬帓搴忛『搴�
-    private Dictionary<UILayer, int> layerSortingOrderCache = new Dictionary<UILayer, int>();
+    private static Dictionary<UILayer, int> layerSortingOrderCache = new Dictionary<UILayer, int>();
     
     // 缂撳瓨灞傜骇瀵瑰簲鐨凾ransform
     private Dictionary<UILayer, Transform> layerTransformCache = new Dictionary<UILayer, Transform>();
@@ -126,17 +131,22 @@
         layerTransformCache.Add(UILayer.Loading, loadingTrans);
     }
     
+    public Transform GetUIRoot()
+    {
+        return uiRoot;
+    }
+    
     #endregion
 
     #region 杈呭姪鏂规硶
-    
+
     // 鑾峰彇UI灞傜骇瀵瑰簲鐨勫熀纭�鎺掑簭椤哄簭
-    private int GetBaseSortingOrderForLayer(UILayer layer)
+    public static int GetBaseSortingOrderForLayer(UILayer layer)
     {
         // 灏濊瘯浠庣紦瀛樹腑鑾峰彇鎺掑簭椤哄簭
         if (layerSortingOrderCache.TryGetValue(layer, out int order))
             return order;
-            
+
         // 濡傛灉缂撳瓨涓病鏈夛紝浣跨敤鍘熸潵鐨勬柟娉曡绠楀苟缂撳瓨缁撴灉
         int result;
         switch (layer)
@@ -151,23 +161,23 @@
                 result = BASE_SORTING_ORDER * 1000;
                 break;
             case UILayer.System:
-                result = BASE_SORTING_ORDER * 10000;
+                result = BASE_SORTING_ORDER * 2000;
                 break;
             case UILayer.Loading:
-                result = BASE_SORTING_ORDER * 100000;
+                result = BASE_SORTING_ORDER * 3000;
                 break;
             default:
                 result = BASE_SORTING_ORDER * 10;
                 break;
         }
-        
+
         // 灏嗙粨鏋滃瓨鍏ョ紦瀛�
         layerSortingOrderCache[layer] = result;
         return result;
     }
 
     // 鑾峰彇灞傜骇瀵瑰簲鐨凾ransform
-    private Transform GetTransForLayer(UILayer layer)
+    public Transform GetTransForLayer(UILayer layer)
     {
         // 灏濊瘯浠庣紦瀛樹腑鑾峰彇Transform
         if (layerTransformCache.TryGetValue(layer, out Transform trans))
@@ -219,6 +229,26 @@
         {
             // 杩斿洖绗竴涓疄渚�
             return uiList[0] as T;
+        }
+
+        // 濡傛灉涓嶅瓨鍦紝杩斿洖null
+        return null;
+    }
+
+    public UIBase GetUI(string uiName)
+    {
+        if (string.IsNullOrEmpty(uiName))
+        {
+            // 璁板綍閿欒鏃ュ織
+            Debug.LogError("UI鍚嶇О涓虹┖");
+            return null;
+        }
+
+        // 灏濊瘯浠庡瓧鍏镐腑鑾峰彇UI瀹炰緥鍒楄〃
+        if (uiDict.TryGetValue(uiName, out List<UIBase> uiList) && uiList.Count > 0)
+        {
+            // 杩斿洖绗竴涓疄渚�
+            return uiList[0];
         }
 
         // 濡傛灉涓嶅瓨鍦紝杩斿洖null
@@ -283,6 +313,72 @@
 
         return false;
     }
+
+    public bool IsOpened(string uiName)
+    {
+        UIBase ui = GetUI(uiName);
+
+        if (null != ui)
+        {
+            return ui.IsActive();
+        }
+
+        return false;
+    }
+
+    // 妫�鏌ユ槸鍚﹀瓨鍦ㄤ换浣曞叏灞忔垨閬僵绐楀彛, 鏈塻creenMask 鍗冲彲浠h〃鍏ㄥ睆
+    public bool ExistAnyFullScreenOrMaskWin(string excludeUIName)
+    {
+        var exist = false;
+        foreach (var uiList in uiDict.Values)
+        {
+            // 閬嶅巻璇ョ被鍨嬬殑鎵�鏈塙I瀹炰緥
+            foreach (var ui in uiList)
+            {
+                // 鍒锋柊UI
+                if (ui.IsActive() && ui.name != excludeUIName)
+                {
+                    if (ui.screenMask != null)
+                    {
+                        exist = true;
+                        break;
+                    }
+                }
+            }
+        }
+
+        return exist;
+    }
+    
+    //鍦ㄦ鐣岄潰涓婃湁娌′换浣曞叏灞忔垨閬僵绐楀彛
+    public bool ExistAnyFullScreenOrMaskWinAbove(string uiName)
+    {
+        var ui = GetUI(uiName);
+        if (ui == null || !ui.IsActive())
+        {
+            // 濡傛灉UI涓嶅瓨鍦ㄦ垨鏈墦寮�锛岄粯璁や负鏈夎鎸′綇 
+            return true;
+        }
+
+        foreach (var uiBase in uiStack)
+        {
+            if (uiBase == null)
+            {
+                continue;
+            }
+            if (uiBase.name == uiName)
+            {
+                break;
+            }
+            if (uiBase.IsActive() && uiBase.screenMask != null)
+            {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
     
     // 鑾峰彇鎸囧畾绫诲瀷鐨勬墍鏈塙I瀹炰緥
     public List<T> GetAllUI<T>() where T : UIBase
@@ -426,7 +522,9 @@
         foreach (var ui in uiToClose)
         {
             // 璁板綍鏃ュ織
+#if UNITY_EDITOR
             Debug.Log($"閿�姣侀暱鏃堕棿鏈娇鐢ㄧ殑UI: {ui.uiName}, 绌洪棽鍥炲悎鏁�: {currentRound - ui.lastUsedRound}");
+#endif
             // 閿�姣乁I瀵硅薄
             GameObject.Destroy(ui.gameObject);
         }
@@ -454,8 +552,17 @@
 
     private UIBase LoadUIResource(string uiName)
     {
+        
         // 浠庤祫婧愮鐞嗗櫒鍔犺浇UI棰勫埗浣�
-        GameObject prefab = ResManager.Instance.LoadAsset<GameObject>("UI", uiName);
+        GameObject prefab;
+        if (uiName == "LaunchWin" || uiName == "DownLoadWin" || uiName == "RequestSecretWin" || uiName == "GameAgeWarnWin")
+        {
+            prefab = BuiltInLoader.LoadPrefab(uiName);
+        }
+        else
+        {
+            prefab = ResManager.Instance.LoadAsset<GameObject>("UI", uiName);
+        }
 
         // 妫�鏌ラ鍒朵綋鏄惁鍔犺浇鎴愬姛
         if (prefab == null)
@@ -525,14 +632,19 @@
         uiStack.CopyTo(uiArray, 0);
         
         // 鍏堟寜鐓ILayer杩涜鎺掑簭锛岀劧鍚庡啀鎸夌収鏍堥『搴忔帓搴�
-        Array.Sort(uiArray, (a, b) => {
-            // 姣旇緝UI灞傜骇
+        Dictionary<UIBase, int> uiOrderDict = new Dictionary<UIBase, int>();
+        for (int i = 0; i < uiArray.Length; i++)
+        {
+            uiOrderDict[uiArray[i]] = i;
+        }
+
+        Array.Sort(uiArray, (a, b) =>
+        {
             int layerCompare = a.uiLayer.CompareTo(b.uiLayer);
             if (layerCompare != 0)
                 return layerCompare;
-                
-            // 鍚屽眰绾у唴锛屾寜鐓ф爤涓殑椤哄簭鎺掑簭
-            return Array.IndexOf(uiArray, b).CompareTo(Array.IndexOf(uiArray, a));
+
+            return uiOrderDict[b].CompareTo(uiOrderDict[a]);
         });
         
         // 閬嶅巻鎺掑簭鍚庣殑UI鏁扮粍锛岃缃帓搴忛『搴�
@@ -545,7 +657,7 @@
             // 璁剧疆UI鐨勬帓搴忛『搴�
             ui.SetSortingOrder(sortingOrder);
             // 鏇存柊褰撳墠鏈�楂樻帓搴忛『搴�
-            currentHighestSortingOrder += 10;
+            currentHighestSortingOrder += ui.uiLayer == UILayer.Static ? 155/*杩欓噷鏄鑹�+鐗规晥涔嬩笂鐨勫眰绾�*/ : 10;
 
             // Debug.Log(ui.uiName + " order is " + sortingOrder + " " + currentHighestSortingOrder);
         }
@@ -559,44 +671,32 @@
 
     private UIBase GetLastSupportParentChildRelationUI()
     {
-        List<UIBase> tempList = new List<UIBase>();
 
-        UIBase target = null;
-
-        while (target == null && uiStack.Count > 0)
+        foreach (var uiBase in uiStack)
         {
-            UIBase uiBase = uiStack.Pop();
-
-            if (uiBase != null && uiBase.supportParentChildRelation && !uiBase.isMainUI)
+            if (uiBase != null && uiBase.supportParentChildRelation)
             {
-                target = uiBase;
+                return uiBase;
             }
-
-            tempList.Add(uiBase);
         }
 
-        for (int i = tempList.Count - 1; i >= 0; i--)
-        {
-            uiStack.Push(tempList[i]);
-        }
-
-        return target;
+        return null;
     }
 
-    public UIBase OpenWindow(string uiName)
+    public UIBase OpenWindow(string uiName, int functionOrder = 0)
     {
         // 浼樺厛浠巆losedUIDict涓幏鍙�
         UIBase parentUI = null;
 
         UIBase returnValue = null;
 
-        Debug.Log("OpenWindow " + uiName);
-
         List<UIBase> closedUIList = new List<UIBase>();
 
         if (closedUIDict.TryGetValue(uiName, out closedUIList) && closedUIList.Count > 0)
         {
+            #if UNITY_EDITOR
             Debug.Log("OpenWindow getFromClosedDict " + uiName);
+            #endif
 
             returnValue = closedUIList[0] as UIBase;
             closedUIList.RemoveAt(0);
@@ -608,7 +708,9 @@
         }
         else
         {
+            #if UNITY_EDITOR
             Debug.Log("OpenWindow getNewLoad " + uiName);
+            #endif
             returnValue = LoadUIResource(uiName);
             if (returnValue == null)
             {
@@ -620,8 +722,8 @@
         
         returnValue.gameObject.SetActive(true);
         
-        // 鑷姩璁剧疆鐖剁骇UI锛堝鏋滄湭鎸囧畾涓旀敮鎸佺埗瀛愬叧绯伙級
-        if (returnValue.supportParentChildRelation && uiStack.Count > 0)
+        // 鑷姩璁剧疆鐖剁骇UI, 濡傛灉鍕鹃�変簡ismainui 鍒欎笉闇�瑕佹壘鐖剁骇UI
+        if (returnValue.supportParentChildRelation && uiStack.Count > 0 && !returnValue.isMainUI)
         {
             // 鑾峰彇鏍堥《UI
             parentUI = GetLastSupportParentChildRelationUI();
@@ -656,7 +758,14 @@
         }
         // 娣诲姞鍒癠I鍒楄〃
         uiDict[uiName].Add(returnValue);
-        
+
+#if UNITY_EDITOR
+        if (uiDict[uiName].Count > 5)
+        { 
+            Debug.LogError("宸叉墦寮�" + uiDict[uiName].Count + "涓晫闈�:" + uiName);
+        }
+#endif
+
         // 灏哢I娣诲姞鍒版爤涓�
         uiStack.Push(returnValue);
         
@@ -664,6 +773,7 @@
         UpdateUISortingOrder();
         
         // 鎵撳紑UI
+        returnValue.functionOrder = functionOrder;
         returnValue.HandleOpen();
 
         OnOpenWindow?.Invoke(returnValue);
@@ -677,11 +787,11 @@
     /// <summary>
     /// 鎵撳紑UI
     /// </summary>
-    public T OpenWindow<T>() where T : UIBase
+    public T OpenWindow<T>(int functionOrder = 0) where T : UIBase
     {
         // 鑾峰彇UI绫诲瀷鍚嶇О
         string uiName = typeof(T).Name;
-        return OpenWindow(uiName) as T;
+        return OpenWindow(uiName, functionOrder) as T;
     }
     
     /// <summary>
@@ -733,8 +843,9 @@
         
         // 鑾峰彇UI绫诲瀷鍚嶇О
         string uiName = ui.uiName;
-
+#if UNITY_EDITOR
         Debug.Log("CloseWindow " + uiName + " destroy : " + destroy.ToString());
+#endif
 
         // 鏀堕泦鎵�鏈夊瓙UI
         List<UIBase> childrenUI = new List<UIBase>();
@@ -760,6 +871,10 @@
             if (tempUI != ui)
             {
                 tempStack.Push(tempUI);
+            }
+            else
+            {
+                break;
             }
         }
         
@@ -791,7 +906,7 @@
         // 鍏抽棴UI
         ui.HandleClose();
         OnCloseWindow?.Invoke(ui);
-        
+
         if (destroy)
         {
             // 閿�姣乁I瀵硅薄
@@ -805,8 +920,10 @@
                 closedUIDict[uiName] = new List<UIBase>();
             }
             closedUIDict[uiName].Add(ui);
-            
+
+#if UNITY_EDITOR
             Debug.Log("CloseWindow " + uiName + " destroy : " + destroy.ToString() + " push to closedUIDict");
+#endif
 
             // 闅愯棌UI (浜ょ粰handle close鍐呴儴鑷繁鍘诲仛)
             // ui.gameObject.SetActive(false);
@@ -843,19 +960,6 @@
         }
     }
 
-    public void ReturnMainUI()
-    {
-        List<UIBase> allUI = new List<UIBase>(uiStack);
-
-        for (int i = 0; i < allUI.Count; i++)
-        {
-            UIBase uiBase = allUI[i];
-            if (!uiBase.isMainUI && uiBase.uiLayer < UILayer.System)
-            {
-                CloseWindow(uiBase);
-            }
-        }
-    }
     
     /// <summary>
     /// 鍏抽棴鎵�鏈塙I

--
Gitblit v1.8.0