lcy
2025-11-06 09bc892c7283df8757a07b646d5af21ddaa263d1
Main/Manager/UIManager.cs
@@ -177,7 +177,7 @@
    }
    // 获取层级对应的Transform
    private Transform GetTransForLayer(UILayer layer)
    public Transform GetTransForLayer(UILayer layer)
    {
        // 尝试从缓存中获取Transform
        if (layerTransformCache.TryGetValue(layer, out Transform trans))
@@ -313,6 +313,72 @@
        return false;
    }
    public bool IsOpened(string uiName)
    {
        UIBase ui = GetUI(uiName);
        if (null != ui)
        {
            return ui.IsActive();
        }
        return false;
    }
    // 检查是否存在任何全屏或遮罩窗口, 有screenMask 即可代表全屏
    public bool ExistAnyFullScreenOrMaskWin(string excludeUIName)
    {
        var exist = false;
        foreach (var uiList in uiDict.Values)
        {
            // 遍历该类型的所有UI实例
            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;
    }
    
    // 获取指定类型的所有UI实例
    public List<T> GetAllUI<T>() where T : UIBase
@@ -591,7 +657,7 @@
            // 设置UI的排序顺序
            ui.SetSortingOrder(sortingOrder);
            // 更新当前最高排序顺序
            currentHighestSortingOrder += ui.uiLayer == UILayer.Static ? 55/*这里是角色+特效之上的层级*/ : 10;
            currentHighestSortingOrder += ui.uiLayer == UILayer.Static ? 155/*这里是角色+特效之上的层级*/ : 10;
            // Debug.Log(ui.uiName + " order is " + sortingOrder + " " + currentHighestSortingOrder);
        }
@@ -605,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)
@@ -668,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();
@@ -818,6 +872,10 @@
            {
                tempStack.Push(tempUI);
            }
            else
            {
                break;
            }
        }
        
        // 将临时栈中的UI重新压入栈中
@@ -902,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>
    /// 关闭所有UI