增加entry排序功能
This commit is contained in:
@@ -140,6 +140,31 @@ namespace XericUI.VisualForm
|
||||
GetWindowState()?.RefreshFlags();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置指定索引条目的排序顺序。Order 越小越在下层,越大越在上层。
|
||||
/// 自动通知 WindowState 重新排列实例的层级顺序。
|
||||
/// </summary>
|
||||
/// <param name="index">条目索引</param>
|
||||
/// <param name="order">排序值</param>
|
||||
public void SetEntryOrder(int index, int order)
|
||||
{
|
||||
if (index < 0 || index >= m_WindowEntries.Count) return;
|
||||
SetEntryOrder(m_WindowEntries[index], order);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 直接通过条目引用设置排序顺序。无需索引查找。
|
||||
/// 自动通知 WindowState 重新排列实例的层级顺序。
|
||||
/// </summary>
|
||||
/// <param name="entry">条目引用</param>
|
||||
/// <param name="order">排序值</param>
|
||||
public void SetEntryOrder(T entry, int order)
|
||||
{
|
||||
if (entry == null) return;
|
||||
entry.SetOrderInternal(order);
|
||||
GetWindowState()?.ApplyEntryOrder();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从所属锚点坞获取自己的中间窗口状态类
|
||||
/// </summary>
|
||||
|
||||
@@ -26,6 +26,9 @@ namespace XericUI.VisualForm
|
||||
[SerializeField, Tooltip("是否参与屏幕空间碰撞分离计算")]
|
||||
private bool m_EnableCollision;
|
||||
|
||||
[SerializeField, Tooltip("排序顺序,值越小越在下层,值越大越在上层")]
|
||||
private int m_Order;
|
||||
|
||||
/// <summary>
|
||||
/// 窗口对象引用(实例或预制体)
|
||||
/// </summary>
|
||||
@@ -63,6 +66,16 @@ namespace XericUI.VisualForm
|
||||
/// </summary>
|
||||
public bool EnableCollision => m_EnableCollision;
|
||||
|
||||
/// <summary>
|
||||
/// 排序顺序 — 值越小越在下层(先渲染),值越大越在上层(后渲染)。
|
||||
/// 运行时修改请通过 AnchorWindow.SetEntryOrder()。
|
||||
/// </summary>
|
||||
public int Order
|
||||
{
|
||||
get => m_Order;
|
||||
set => SetOrderInternal(value);
|
||||
}
|
||||
|
||||
// --- 运行时状态(非序列化) ---
|
||||
|
||||
/// <summary>
|
||||
@@ -115,6 +128,7 @@ namespace XericUI.VisualForm
|
||||
internal void SetEnabledInternal(bool value) { m_Enabled = value; MarkDirty(); }
|
||||
internal void SetClampToSafeZoneInternal(bool value) { m_ClampToSafeZone = value; MarkDirty(); }
|
||||
internal void SetEnableCollisionInternal(bool value) { m_EnableCollision = value; MarkDirty(); }
|
||||
internal void SetOrderInternal(int value) { m_Order = value; MarkDirty(); }
|
||||
|
||||
// --- 依赖脏标记 ---
|
||||
|
||||
|
||||
@@ -152,6 +152,7 @@ namespace XericUI.VisualForm
|
||||
}
|
||||
|
||||
RefreshFlags();
|
||||
ApplyEntryOrder();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -400,6 +401,30 @@ namespace XericUI.VisualForm
|
||||
|
||||
#endregion
|
||||
|
||||
#region 排序
|
||||
|
||||
/// <summary>
|
||||
/// 按条目的 Order 字段升序排列实例的层级顺序。
|
||||
/// Order 越小越在下层(先渲染),Order 越大越在上层(后渲染)。
|
||||
/// 在 ResolveWindowEntries 完成后调用,也可在运行时通过 AnchorWindow.SetEntryOrder 触发。
|
||||
/// </summary>
|
||||
internal void ApplyEntryOrder()
|
||||
{
|
||||
if (Entries == null || Entries.Count <= 1) return;
|
||||
|
||||
// 按Order升序 → SetAsLastSibling:结果就是 Order 越小 siblingIndex 越小(下层),Order 越大 siblingIndex 越大(上层)
|
||||
var sorted = new List<WindowEntry>(Entries);
|
||||
sorted.Sort((a, b) => a.Order.CompareTo(b.Order));
|
||||
|
||||
foreach (var entry in sorted)
|
||||
{
|
||||
if (entry.Instance != null)
|
||||
entry.Instance.transform.SetAsLastSibling();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 检查锚点坐标是否发生变化,超过阈值则标记脏
|
||||
/// 由锚点坞在每帧调用
|
||||
|
||||
Reference in New Issue
Block a user