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

添加支持自动可见性剔除的滚动管理器。
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
@@ -0,0 +1,80 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Pool;
using UnityEngine.UI;
using XericLibrary.Runtime.MacroLibrary;
namespace XericUI.OverrideLayout
{
[AddComponentMenu("Xeric UI Vessel/Layout/Xeric Horizontal Layout Group")]
/// <summary>
/// Layout child layout elements below each other.
/// </summary>
public class XericHorizontalLayoutGroup: XericHorizontalOrVerticalLayoutGroup
{
protected XericHorizontalLayoutGroup()
{}
/// <summary>
/// Called by the layout system. Also see ILayoutElement
/// </summary>
public override void CalculateLayoutInputHorizontal()
{
rectChildren.Clear();
var toIgnoreList = ListPool<Component>.Get();
for (int i = 0; i < rectTransform.childCount; i++)
{
var rect = rectTransform.GetChild(i) as RectTransform;
if (rect == null ||
(layoutIgnoreInactive && !rect.gameObject.activeInHierarchy))
continue;
rect.GetComponents(typeof(ILayoutIgnorer), toIgnoreList);
if (toIgnoreList.Count == 0)
{
rectChildren.Add(rect);
continue;
}
for (int j = 0; j < toIgnoreList.Count; j++)
{
var ignorer = (ILayoutIgnorer)toIgnoreList[j];
if (!ignorer.ignoreLayout)
{
rectChildren.Add(rect);
break;
}
}
}
ListPool<Component>.Release(toIgnoreList);
m_Tracker.Clear();
CalcAlongAxis(0, false);
}
/// <summary>
/// Called by the layout system. Also see ILayoutElement
/// </summary>
public override void CalculateLayoutInputVertical()
{
CalcAlongAxis(1, false);
}
/// <summary>
/// Called by the layout system. Also see ILayoutElement
/// </summary>
public override void SetLayoutHorizontal()
{
SetChildrenAlongAxis(0, false);
}
/// <summary>
/// Called by the layout system. Also see ILayoutElement
/// </summary>
public override void SetLayoutVertical()
{
SetChildrenAlongAxis(1, false);
}
}
}