AlicizaX/Client/Packages/com.alicizax.unity.ui/Runtime/UI/Base/Manager/UIManager.Root.cs
2025-01-24 16:21:00 +08:00

95 lines
2.7 KiB
C#

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<Canvas>();
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<RectTransform>();
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<PanelInfo>(16));
//算上持续缓存的 感觉一个层级 不可能同时有16个界面驻留吧??分层做处理也可以
}
InitAddUIBlock();
}
public RectTransform GetLayerRect(UILayer panelLayer)
{
return m_AllWindowLayer[(int)panelLayer];
}
}
}