using System.Collections.Generic; using UnityEngine; namespace AlicizaX.UI.Runtime { internal sealed partial class UIManager { public Camera UICamera { get; set; } public Canvas UICanvas; public Transform UICanvasRoot { get; set; } public Transform UIRoot; private const int RootPosOffset = 1000; private const int LayerDistance = 1000; private const int LAYER_DEEP = 2000; private const int WINDOW_DEEP = 100; private readonly RectTransform[] m_AllWindowLayer = new RectTransform[(int)UILayer.All]; #region 快捷获取层级 private RectTransform m_UICache; public RectTransform UICache { get { if (m_UICache == null) { m_UICache = GetLayerRect(UILayer.Cache); } return m_UICache; } } private RectTransform m_UIPanel; public RectTransform UIPanel { get { if (m_UIPanel == null) { m_UIPanel = GetLayerRect(UILayer.UI); } return m_UIPanel; } } #endregion public void Initlize(Transform root) { UIRoot = root; Object.DontDestroyOnLoad(root.gameObject); UIRoot.transform.position = new Vector3(RootPosOffset, RootPosOffset, 0); UICanvas = UIRoot.GetComponentInChildren(); UICamera = UICanvas.worldCamera; UICanvasRoot = UICanvas.transform; const int len = (int)UILayer.All; for (var i = len - 1; i >= 0; i--) { var layer = new GameObject($"Layer{i}-{(UILayer)i}"); var rect = layer.AddComponent(); rect.SetParent(UICanvasRoot); rect.localScale = Vector3.one; rect.pivot = new Vector2(0.5f, 0.5f); rect.anchorMax = Vector2.one; rect.anchorMin = Vector2.zero; rect.sizeDelta = Vector2.zero; rect.localRotation = Quaternion.identity; rect.localPosition = new Vector3(0, 0, i * LayerDistance); m_AllWindowLayer[i] = rect; mShowUIWindow.Add((UILayer)i, new List(16)); //算上持续缓存的 感觉一个层级 不可能同时有16个界面驻留吧??分层做处理也可以 } InitAddUIBlock(); } public RectTransform GetLayerRect(UILayer panelLayer) { return m_AllWindowLayer[(int)panelLayer]; } } }