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 |  165 +++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 118 insertions(+), 47 deletions(-)

diff --git a/Main/Manager/UIManager.cs b/Main/Manager/UIManager.cs
index a3bee2c..eed236b 100644
--- a/Main/Manager/UIManager.cs
+++ b/Main/Manager/UIManager.cs
@@ -50,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>();
@@ -131,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)
@@ -156,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))
@@ -308,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
@@ -481,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)
@@ -552,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鏁扮粍锛岃缃帓搴忛『搴�
@@ -572,7 +657,7 @@
             // 璁剧疆UI鐨勬帓搴忛『搴�
             ui.SetSortingOrder(sortingOrder);
             // 鏇存柊褰撳墠鏈�楂樻帓搴忛『搴�
-            currentHighestSortingOrder += 10;
+            currentHighestSortingOrder += ui.uiLayer == UILayer.Static ? 155/*杩欓噷鏄鑹�+鐗规晥涔嬩笂鐨勫眰绾�*/ : 10;
 
             // Debug.Log(ui.uiName + " order is " + sortingOrder + " " + currentHighestSortingOrder);
         }
@@ -586,28 +671,16 @@
 
     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, int functionOrder = 0)
@@ -649,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();
@@ -685,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);
         
@@ -792,6 +872,10 @@
             {
                 tempStack.Push(tempUI);
             }
+            else
+            {
+                break;
+            }
         }
         
         // 灏嗕复鏃舵爤涓殑UI閲嶆柊鍘嬪叆鏍堜腑
@@ -876,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