From d4b7848dde122985194d679c2c869a381d379953 Mon Sep 17 00:00:00 2001
From: LiRuoChen <571244399@qq.com>
Date: Fri, 12 Jun 2026 09:17:30 +0800
Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=94=9A=E7=82=B9=E7=AA=97?=
=?UTF-8?q?=E5=8F=A3=E7=BB=84=E4=BB=B6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Runtime/VisualForm.meta | 8 +
Runtime/VisualForm/AnchorDock.cs | 535 ++++++++++++++++++++++++
Runtime/VisualForm/AnchorDock.cs.meta | 11 +
Runtime/VisualForm/AnchorWindow.cs | 147 +++++++
Runtime/VisualForm/AnchorWindow.cs.meta | 11 +
Runtime/VisualForm/WindowPool.cs | 115 +++++
Runtime/VisualForm/WindowPool.cs.meta | 11 +
Runtime/VisualForm/WindowState.cs | 224 ++++++++++
Runtime/VisualForm/WindowState.cs.meta | 11 +
Runtime/VisualForm/WorldAnchor.cs | 71 ++++
Runtime/VisualForm/WorldAnchor.cs.meta | 11 +
Runtime/VisualForm/XVFormBase.cs | 51 +++
Runtime/VisualForm/XVFormBase.cs.meta | 11 +
13 files changed, 1217 insertions(+)
create mode 100644 Runtime/VisualForm.meta
create mode 100644 Runtime/VisualForm/AnchorDock.cs
create mode 100644 Runtime/VisualForm/AnchorDock.cs.meta
create mode 100644 Runtime/VisualForm/AnchorWindow.cs
create mode 100644 Runtime/VisualForm/AnchorWindow.cs.meta
create mode 100644 Runtime/VisualForm/WindowPool.cs
create mode 100644 Runtime/VisualForm/WindowPool.cs.meta
create mode 100644 Runtime/VisualForm/WindowState.cs
create mode 100644 Runtime/VisualForm/WindowState.cs.meta
create mode 100644 Runtime/VisualForm/WorldAnchor.cs
create mode 100644 Runtime/VisualForm/WorldAnchor.cs.meta
create mode 100644 Runtime/VisualForm/XVFormBase.cs
create mode 100644 Runtime/VisualForm/XVFormBase.cs.meta
diff --git a/Runtime/VisualForm.meta b/Runtime/VisualForm.meta
new file mode 100644
index 0000000..2d1f31e
--- /dev/null
+++ b/Runtime/VisualForm.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: bbfebc997f9b7fc42931055da4745128
+folderAsset: yes
+DefaultImporter:
+ externalObjects: {}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Runtime/VisualForm/AnchorDock.cs b/Runtime/VisualForm/AnchorDock.cs
new file mode 100644
index 0000000..9ed8697
--- /dev/null
+++ b/Runtime/VisualForm/AnchorDock.cs
@@ -0,0 +1,535 @@
+using System.Collections.Generic;
+using UnityEngine;
+using UnityEngine.UI;
+
+namespace XericUI.VisualForm
+{
+ ///
+ /// 锚点坞 - 挂载在Canvas上的主要布局组件管理器。
+ /// 负责收集所有世界锚点,每帧将世界坐标转换到屏幕坐标,并管理中间窗口状态。
+ ///
+ [AddComponentMenu("Xeric UI Vessel/AnchorWindow/AnchorDock")]
+ public class AnchorDock : MonoBehaviour
+ {
+ [Header("配置")]
+ [SerializeField, Tooltip("指定摄像机,不填则自动检测")]
+ private Camera m_OverrideCamera;
+
+ [SerializeField, Tooltip("坐标变化阈值,移动超过此值才会标记坐标脏")]
+ private float m_PositionThreshold = 0.1f;
+
+ [Space]
+ [SerializeField, Tooltip("预注册的锚点列表(坞可直接标记要使用的窗口锚点,双方引用有一个可不填)")]
+ private List m_TargetAnchors = new List();
+
+ [SerializeField, Tooltip("预分配的中间类对象池容量")]
+ private int m_StatePoolPreallocate = 16;
+
+ #region 静态单例
+
+ private static AnchorDock s_Main;
+
+ ///
+ /// 主要的静态单例锚点坞引用
+ ///
+ public static AnchorDock Main => s_Main;
+
+ ///
+ /// 待注册锚点列表 — 锚点在OnEnable时找不到坞,将自己暂存于此,等待坞后续处理
+ ///
+ internal static readonly HashSet s_PendingAnchors = new HashSet();
+
+ #endregion
+
+ #region 内部状态
+
+ private Canvas _canvas;
+ private Camera _renderCamera;
+ private RectTransform _rectTransform;
+
+ ///
+ /// 锚点集合(HashSet用于O(1)去重和查找)
+ ///
+ private readonly HashSet _anchorSet = new HashSet();
+
+ ///
+ /// 锚点脏标记 - 有新增或移除时为true,延迟到下一帧处理
+ ///
+ private bool _anchorsDirty;
+
+ ///
+ /// 待新增锚点列表(脏更新期间收集)
+ ///
+ private readonly List _pendingAdds = new List();
+
+ ///
+ /// 待移除锚点列表(脏更新期间收集)
+ ///
+ private readonly List _pendingRemoves = new List();
+
+ ///
+ /// 活跃的窗口状态字典:锚点 -> 中间窗口状态类
+ ///
+ private readonly Dictionary _activeStates = new Dictionary();
+
+ ///
+ /// 中间类对象池
+ ///
+ private readonly Queue _statePool = new Queue();
+
+ ///
+ /// 子对象哈希集 - 用于O(1)快速检查对象是否在子项中
+ ///
+ private readonly HashSet _childrenHashSet = new HashSet();
+
+ ///
+ /// 子对象哈希集脏标记
+ ///
+ private bool _childrenSetDirty = true;
+
+ ///
+ /// 摄像机变换脏标记
+ ///
+ private bool _cameraDirty;
+
+ ///
+ /// 上帧摄像机世界坐标
+ ///
+ private Vector3 _lastCameraPosition;
+
+ ///
+ /// 上帧摄像机世界旋转
+ ///
+ private Quaternion _lastCameraRotation;
+
+ #endregion
+
+ #region 公开属性
+
+ ///
+ /// 当前使用的渲染摄像机
+ ///
+ public Camera RenderCamera => _renderCamera;
+
+ ///
+ /// Canvas组件引用
+ ///
+ public Canvas Canvas => _canvas;
+
+ ///
+ /// RectTransform引用
+ ///
+ public RectTransform RectTransform
+ {
+ get
+ {
+ if (_rectTransform == null)
+ _rectTransform = GetComponent();
+ return _rectTransform;
+ }
+ }
+
+ ///
+ /// 坐标变化阈值
+ ///
+ public float PositionThreshold => m_PositionThreshold;
+
+ #endregion
+
+ #region 生命周期
+
+ protected virtual void Awake()
+ {
+ // 在Awake阶段注册单例
+ s_Main = this;
+ }
+
+ protected virtual void OnEnable()
+ {
+ _canvas = GetComponentInParent