| | |
| | | layerTransformCache.Add(UILayer.Loading, loadingTrans); |
| | | } |
| | | |
| | | public Transform GetUIRoot() |
| | | { |
| | | return uiRoot; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region 辅助方法 |
| | | |
| | | |
| | | // 获取UI层级对应的基础排序顺序 |
| | | public static int GetBaseSortingOrderForLayer(UILayer layer) |
| | | { |
| | | // 尝试从缓存中获取排序顺序 |
| | | if (layerSortingOrderCache.TryGetValue(layer, out int order)) |
| | | return order; |
| | | |
| | | |
| | | // 如果缓存中没有,使用原来的方法计算并缓存结果 |
| | | int result; |
| | | switch (layer) |
| | |
| | | result = BASE_SORTING_ORDER * 10; |
| | | break; |
| | | } |
| | | |
| | | |
| | | // 将结果存入缓存 |
| | | layerSortingOrderCache[layer] = result; |
| | | return result; |
| | | } |
| | | |
| | | // 获取层级对应的Transform |
| | | private Transform GetTransForLayer(UILayer layer) |
| | | public Transform GetTransForLayer(UILayer layer) |
| | | { |
| | | // 尝试从缓存中获取Transform |
| | | if (layerTransformCache.TryGetValue(layer, out Transform trans)) |
| | |
| | | |
| | | 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 |
| | |
| | | |
| | | 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) |
| | |
| | | |
| | | 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(); |
| | |
| | | { |
| | | tempStack.Push(tempUI); |
| | | } |
| | | else |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | |
| | | // 将临时栈中的UI重新压入栈中 |
| | |
| | | } |
| | | } |
| | | |
| | | 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 |