From bb8ba1bb9ff2db20711b264ba7bc3f01397a99f7 Mon Sep 17 00:00:00 2001 From: LiRuoChen <571244399@qq.com> Date: Wed, 17 Jun 2026 11:53:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0entry=E6=8E=92=E5=BA=8F?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Runtime/VisualForm/AnchorWindow.cs | 25 +++++++++++++++++++++++++ Runtime/VisualForm/WindowEntry.cs | 14 ++++++++++++++ Runtime/VisualForm/WindowState.cs | 25 +++++++++++++++++++++++++ 3 files changed, 64 insertions(+) diff --git a/Runtime/VisualForm/AnchorWindow.cs b/Runtime/VisualForm/AnchorWindow.cs index c918c73..0a6b234 100644 --- a/Runtime/VisualForm/AnchorWindow.cs +++ b/Runtime/VisualForm/AnchorWindow.cs @@ -140,6 +140,31 @@ namespace XericUI.VisualForm GetWindowState()?.RefreshFlags(); } + /// + /// 设置指定索引条目的排序顺序。Order 越小越在下层,越大越在上层。 + /// 自动通知 WindowState 重新排列实例的层级顺序。 + /// + /// 条目索引 + /// 排序值 + public void SetEntryOrder(int index, int order) + { + if (index < 0 || index >= m_WindowEntries.Count) return; + SetEntryOrder(m_WindowEntries[index], order); + } + + /// + /// 直接通过条目引用设置排序顺序。无需索引查找。 + /// 自动通知 WindowState 重新排列实例的层级顺序。 + /// + /// 条目引用 + /// 排序值 + public void SetEntryOrder(T entry, int order) + { + if (entry == null) return; + entry.SetOrderInternal(order); + GetWindowState()?.ApplyEntryOrder(); + } + /// /// 从所属锚点坞获取自己的中间窗口状态类 /// diff --git a/Runtime/VisualForm/WindowEntry.cs b/Runtime/VisualForm/WindowEntry.cs index 1f2858b..d86d539 100644 --- a/Runtime/VisualForm/WindowEntry.cs +++ b/Runtime/VisualForm/WindowEntry.cs @@ -26,6 +26,9 @@ namespace XericUI.VisualForm [SerializeField, Tooltip("是否参与屏幕空间碰撞分离计算")] private bool m_EnableCollision; + [SerializeField, Tooltip("排序顺序,值越小越在下层,值越大越在上层")] + private int m_Order; + /// /// 窗口对象引用(实例或预制体) /// @@ -63,6 +66,16 @@ namespace XericUI.VisualForm /// public bool EnableCollision => m_EnableCollision; + /// + /// 排序顺序 — 值越小越在下层(先渲染),值越大越在上层(后渲染)。 + /// 运行时修改请通过 AnchorWindow.SetEntryOrder()。 + /// + public int Order + { + get => m_Order; + set => SetOrderInternal(value); + } + // --- 运行时状态(非序列化) --- /// @@ -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(); } // --- 依赖脏标记 --- diff --git a/Runtime/VisualForm/WindowState.cs b/Runtime/VisualForm/WindowState.cs index 2f76d87..21f3bd8 100644 --- a/Runtime/VisualForm/WindowState.cs +++ b/Runtime/VisualForm/WindowState.cs @@ -152,6 +152,7 @@ namespace XericUI.VisualForm } RefreshFlags(); + ApplyEntryOrder(); } /// @@ -400,6 +401,30 @@ namespace XericUI.VisualForm #endregion + #region 排序 + + /// + /// 按条目的 Order 字段升序排列实例的层级顺序。 + /// Order 越小越在下层(先渲染),Order 越大越在上层(后渲染)。 + /// 在 ResolveWindowEntries 完成后调用,也可在运行时通过 AnchorWindow.SetEntryOrder 触发。 + /// + internal void ApplyEntryOrder() + { + if (Entries == null || Entries.Count <= 1) return; + + // 按Order升序 → SetAsLastSibling:结果就是 Order 越小 siblingIndex 越小(下层),Order 越大 siblingIndex 越大(上层) + var sorted = new List(Entries); + sorted.Sort((a, b) => a.Order.CompareTo(b.Order)); + + foreach (var entry in sorted) + { + if (entry.Instance != null) + entry.Instance.transform.SetAsLastSibling(); + } + } + + #endregion + /// /// 检查锚点坐标是否发生变化,超过阈值则标记脏 /// 由锚点坞在每帧调用