添加水平与垂直布局的重写管理,支持对不可见对象的布局计算。

添加支持自动可见性剔除的滚动管理器。
This commit is contained in:
2025-09-17 19:51:16 +08:00
parent 28a96e1fd8
commit ddb6806a9b
17 changed files with 590 additions and 6 deletions
+104 -6
View File
@@ -2,6 +2,7 @@
using Sirenix.OdinInspector;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace XericUI.Core.Base
{
@@ -11,11 +12,85 @@ namespace XericUI.Core.Base
[HideLabel, DisplayAsString]
string __EMPTYFIELD;
protected bool PublicFieldNullReference;
[System.NonSerialized] private Canvas _canvas;
[System.NonSerialized] private CanvasScaler _canvasScaler;
[System.NonSerialized] private GraphicRaycaster _graphicRaycaster;
[System.NonSerialized] private RectTransform _rect;
/// <summary>
/// 层级脏(层级被转移)
/// </summary>
private bool _hierarchyDirty;
/// <summary>
/// 根布局管理器
/// </summary>
public Canvas canvas
{
get
{
if (_canvas == null)
_canvas = GetComponentInParent<Canvas>();
#if UNITY_EDITOR
if (_canvas == null)
Debug.LogError($"{name} 无法找到布局组件,接下来的流程可能会引发错误", this);
#endif
return _canvas;
}
}
/// <summary>
/// 根布局缩放
/// </summary>
public CanvasScaler canvasScaler
{
get
{
if (_canvasScaler == null)
_canvasScaler = GetComponentInParent<CanvasScaler>();
#if UNITY_EDITOR
if (_canvas == null)
Debug.LogError($"{name} 无法找到布局缩放组件,接下来的流程可能会引发错误", this);
#endif
return _canvasScaler;
}
}
/// <summary>
/// 根布局射线检测
/// </summary>
public GraphicRaycaster graphicRaycaster
{
get
{
if (_graphicRaycaster == null)
_graphicRaycaster = GetComponentInParent<GraphicRaycaster>();
#if UNITY_EDITOR
if (_canvas == null)
Debug.LogError($"{name} 无法找到布局射线检测,接下来的流程可能会引发错误", this);
#endif
return _graphicRaycaster;
}
}
/// <summary>
/// ui变换组件
/// </summary>
protected RectTransform rectTransform
{
get
{
if (_rect == null)
_rect = GetComponent<RectTransform>();
return _rect;
}
}
#region 生命周期
protected bool AlreadyAwake { get; private set; }
protected bool AlreadyStart { get; private set; }
protected bool AlreadyOnEnable { get; private set; }
@@ -37,7 +112,7 @@ namespace XericUI.Core.Base
protected override void OnEnable()
{
AlreadyOnEnable = true;
AlreadyOnEnable = true;
base.OnEnable();
}
@@ -46,6 +121,29 @@ namespace XericUI.Core.Base
AlreadyOnDisable = true;
base.OnDisable();
}
#endregion
#region 脏处理
/// <summary>
/// 设置层级脏
/// </summary>
public void SetHierarchyDirty()
{
_canvas = null;
_canvasScaler = null;
_graphicRaycaster = null;
_hierarchyDirty = true;
}
/// <summary>
/// 复位层级脏
/// </summary>
public void ResetHierarchyDirty()
{
_hierarchyDirty = false;
}
#endregion
}
}