表格:背景/边框的图元原点按"rect 中心"摆放;调试开关覆盖整棵生成层级
坐标错位的真正来源在图元渲染器的上游:PrimitiveCacheRendererBase / CacheLineRendererBase 把 子块建成"铺满本渲染器、轴心 0.5"的对象,顶点直接放在子块本地空间 ⇒ 图元坐标的原点是 rect 的<b>中心</b>,不是左上角。表格喂的是左上角坐标,于是背景与边框(两者都是图元渲染器) 一起偏了半个尺寸、彼此严丝合缝,却和文本(UGUI 左上角语义)对不上。 - 新增 PinPrimitiveRect:锚点 (0,1)、轴心 0.5、锚位放在左上角 ⇒ rect 中心(即网格原点) 与左上角重合;背景、边框、冻结边框都改走它,绘图代码保持左上角语义不变。 - 撤回上一版按 rectTransform.rect 换算原点的做法(那个假设是错的)。 - SetChildrenVisible 改为遍历整棵生成层级(模板/背景/边框/冻结层/池化单元格), 显示时只去掉 HideInHierarchy、保留 NotEditable:调试视图能看到每一个生成物。
This commit is contained in:
@@ -222,6 +222,24 @@ namespace XericUI.XTable.Rendering.Component
|
||||
if (rt.anchoredPosition != position) rt.anchoredPosition = position;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 图元渲染器(背景/边框)专用:它们的子块铺满本渲染器且轴心 0.5,顶点原点=rect 的<b>中心</b>。
|
||||
/// 所以让这个 rect 的"中心"落在左上角(pivot 0.5 + 锚点 (0,1) + 锚位 0),
|
||||
/// 绘图代码就能继续用左上角坐标,和文本(UGUI 左上角语义)对得上。
|
||||
/// </summary>
|
||||
private static void PinPrimitiveRect(RectTransform rt, Vector2 position, float width, float height)
|
||||
{
|
||||
if (rt == null) return;
|
||||
Vector2 topLeft = new Vector2(0f, 1f);
|
||||
Vector2 center = new Vector2(0.5f, 0.5f);
|
||||
if (rt.anchorMin != topLeft) rt.anchorMin = topLeft;
|
||||
if (rt.anchorMax != topLeft) rt.anchorMax = topLeft;
|
||||
if (rt.pivot != center) rt.pivot = center;
|
||||
if (rt.anchoredPosition != position) rt.anchoredPosition = position;
|
||||
var size = new Vector2(width, height);
|
||||
if (rt.sizeDelta != size) rt.sizeDelta = size;
|
||||
}
|
||||
|
||||
/// <summary>同上,顺带把尺寸一起钉死。</summary>
|
||||
private static void PinTopLeftRect(RectTransform rt, Vector2 position, float width, float height)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user