表格:编辑器模式不再把运行时布局写成预制体覆盖

- 生成物 hideFlags 增加 NotEditable:编辑期的自动改动不会被记成预制体覆盖。
- 域重载后按名字收养已存在的 _TableBackground/_TableBorders(普通字段为 null,DontSave 的
  对象还活着),否则每次重载都会再叠一层。
- content 与冻结容器的尺寸/位置改用 DrivenRectTransformTracker 写入,值每次重算、不落序列化。
This commit is contained in:
2026-11-13 15:19:50 +08:00
parent d861ea60fc
commit e23150bfda
4 changed files with 32 additions and 5 deletions
@@ -62,18 +62,32 @@ namespace XericUI.XTable.Rendering.Component
public void CreateBackground(float width, float height, string styleNamespace, Vector2 position = default)
{
if (m_BackgroundGo == null && m_Parent != null)
{
// 背景缓存是普通字段,域重载后为 null;容器里 DontSave 的 _TableBackground 还活着。
// 三个冻结渲染器各有自己的容器,按名字收养是安全的;不收养每次重载都会多叠一层。
var existing = m_Parent.Find("_TableBackground");
if (existing != null) m_BackgroundGo = existing.gameObject;
}
if (m_BackgroundGo == null)
{
m_BackgroundGo = new GameObject("_TableBackground", typeof(RectTransform), typeof(CanvasRenderer), typeof(Image), typeof(XTableSelectionInput));
m_BackgroundGo.hideFlags = HideFlags.DontSave | HideFlags.HideInHierarchy;
// NotEditable:编辑期改它不会被记成预制体覆盖。
m_BackgroundGo.hideFlags = HideFlags.DontSave | HideFlags.HideInHierarchy | HideFlags.NotEditable;
m_BackgroundGo.transform.SetParent(m_Parent, false);
m_BackgroundGo.transform.SetAsFirstSibling();
var image = m_BackgroundGo.GetComponent<Image>();
}
// 收养来的对象也要重新配置一次,颜色/选择输入不能沿用上一次的。
var image = m_BackgroundGo.GetComponent<Image>();
if (image != null)
{
image.raycastTarget = true;
m_BackgroundGo.GetComponent<XTableSelectionInput>().Configure(SelectionTable);
image.color = GetStyleColor?.Invoke(styleNamespace, XericUIActionTable.STYLE_CELL_BG_COLOR,
XericUIActionTable.BG_COLOR_FALLBACK) ?? XericUIActionTable.BG_COLOR_FALLBACK;
}
var selectionInput = m_BackgroundGo.GetComponent<XTableSelectionInput>();
if (selectionInput != null) selectionInput.Configure(SelectionTable);
var rt = m_BackgroundGo.GetComponent<RectTransform>();
rt.anchorMin = new Vector2(0, 1);
rt.anchorMax = new Vector2(0, 1);