- Awake 与三个重建入口不再"先清空再重建",改走 ReconcileGeneratedHierarchy:模板、背景、 边框、冻结层逐项检查,存在就复用(各自重置 rect 与内容),缺了才建。编辑模式下预制体实例 里的对象本来就不能 DestroyImmediate,这条路径也顺手绕开了它。 - 池的四个显隐回调与 ReleaseAllTrackedCells 跳过已销毁的根:手工删过生成物之后, ReturnCounter 会把已销毁对象交给 SetActive,抛 MissingReferenceException。 - XTableBackgroundRenderer 的图元坐标按 rectTransform.rect 换算:本地原点是轴心、图元坐标是 左上角原点,以前只在 pivot=(0,1) 时重合;现在轴心是什么都对,不再依赖调用方先摆好 pivot。
63 lines
2.4 KiB
C#
63 lines
2.4 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using XericLibrary.Runtime.UIGraph;
|
|
using PrimitiveType = XericLibrary.Runtime.UIGraph.PrimitiveType;
|
|
|
|
namespace XericUI.XTable.Rendering.Elements
|
|
{
|
|
/// <summary>用于批量绘制 XTable 背景区域的图元渲染器。</summary>
|
|
public sealed class XTableBackgroundRenderer : PrimitiveCacheRendererBase
|
|
{
|
|
/// <summary>以左上角为原点的背景区域及其填充颜色。</summary>
|
|
public struct RectData
|
|
{
|
|
public Rect Rect;
|
|
public Color Color;
|
|
|
|
public RectData(Rect rect, Color color)
|
|
{
|
|
Rect = rect;
|
|
Color = color;
|
|
}
|
|
}
|
|
|
|
/// <summary>以左上角坐标系替换全部背景矩形。</summary>
|
|
public void ReplaceRects(IReadOnlyList<RectData> rects)
|
|
{
|
|
ClearAll();
|
|
if (rects == null) return;
|
|
|
|
// 图元坐标是"以矩形左上角为原点",而基类把顶点直接放在渲染器的<b>本地空间</b>
|
|
// (本地原点是轴心,不是左上角)。这里按 rectTransform.rect 把两套原点对上:
|
|
// 轴心是 (0,1) 还是 (0.5,0.5) 结果都一样——不再依赖调用方先把 pivot 摆对。
|
|
Rect local = rectTransform.rect;
|
|
float originX = local.x;
|
|
float originY = local.y + local.height;
|
|
|
|
for (int i = 0; i < rects.Count; i++)
|
|
{
|
|
RectData rectData = rects[i];
|
|
Rect rect = rectData.Rect;
|
|
AddPrimitive(new PrimitiveCacheEntry
|
|
{
|
|
type = PrimitiveType.Rectangle,
|
|
sizeMode = SizeMode.InscribedEllipse,
|
|
center = new Vector2(originX + rect.x + rect.width * 0.5f,
|
|
originY - (rect.y + rect.height * 0.5f)),
|
|
size = rect.size,
|
|
@params = new PrimitiveParams
|
|
{
|
|
axisScaleX = 1f,
|
|
axisScaleY = 1f,
|
|
chamferSegments = 1,
|
|
bgColor = rectData.Color,
|
|
centerColor = rectData.Color,
|
|
borderColor = Color.clear,
|
|
borderThickness = 0f,
|
|
},
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|