XChart 图表框架落地(P0–P17):格线单一作者、面板一行状态、矢量场
此前整个 XChart 特性一直没有提交(分期 P0–P12 的代码与素材都还在工作区里)。这一批一并入库, 并含本轮 P13–P17 的改动(规范 Documentation/XChart-RenderFramework.md 新增 §22–§25): - P13:格线只剩一个作者——线框工具不再有"画格线 / 发布格线插槽"的代码路径;BG Cube Grid(原 MeshBg) 是唯一作者,且"画上去的线=发布给轴线的那份比例数组";插槽板新增 Unpublish(说得出"这里不再有线", 否则掩码筛掉的面会把上一轮的值留着被消费者吸走);渲染参数搬进元素表 (DeclareDefaultElements / AddDefaultElement + XChartElementTable 按类型去重,只在第一次读到表时补); 图上「立方体外观」那组字段删除、公共属性转发到元素表;面板逐行点名脚本注册的工具。 - P14 / P15:数据窗口文案收敛(行末 `-`、标题 `X [0]`、长说明退回 tooltip、范围页三行不再被压扁); 元素块收成一行状态 `▼ 名称 √ R… D… [↑][↓][-]`;**注册序由类型定死、只显示不给输入控件, 绘制序与元素在表里的位置绑定**(§24.5,他 2026-10-25 澄清);默认元素让删也让关; EnsureSpace 改成每次重建后都跑(删掉"空间"不再等于整张图空掉)。 - P17:矢量场——维数不够时不再静默不画(元素配置报需求,面板与报表同时印"需求/现有"); 相对/绝对两种读法收进纯算术 XChartVectorFieldMath;连续绘制(互斥显示把"相对/绝对"藏起来); 颜色维(色相走 0..256 色环,饱和/明度/不透明 0..1,不透明度不算硬需求);新增螺旋矢量场测试数据。 数据口径按他澄清修正为:前三维=坐标、一支箭头=相邻两条记录、第 4~7 维是颜色(§25、CHANGELOG 修正行)。 判据:编译门三臂 + 3 支对照绿;离线探针 436 项 0 失败;p4_control 55 支臂各红在自己点名的断言上; p2_control / pool_family / generator_gate / hierarchy_gate 在同一棵交付树上复跑。 (证据脚本与日志在包外的 .ximage-gate/,未入本仓库。)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using UnityEngine;
|
||||
using XericLibrary.Runtime.UIGraph;
|
||||
using TMPro;
|
||||
using XericUI.Core;
|
||||
|
||||
namespace XericUI.XChart.Radar
|
||||
{
|
||||
@@ -21,7 +22,7 @@ namespace XericUI.XChart.Radar
|
||||
/// ├─ Label_1 (TMP_Text)
|
||||
/// └─ ...
|
||||
/// </summary>
|
||||
[AddComponentMenu("Xeric/XChart/Radar/Radar Background Tool")]
|
||||
[AddComponentMenu(XericRegistrationPaths.Chart + "/Radar/Radar Background Tool")]
|
||||
public class ChartToolRadarBg : XChartToolBase
|
||||
{
|
||||
// ── 配置 ──────────────────────────────────────────────────
|
||||
@@ -79,11 +80,12 @@ namespace XericUI.XChart.Radar
|
||||
/// <summary>轴线渲染器</summary>
|
||||
public UILineRendererV2 AxisRenderer { get; private set; }
|
||||
|
||||
/// <summary>标签的父变换</summary>
|
||||
public Transform LabelsRoot { get; private set; }
|
||||
|
||||
/// <summary>所有标签文本组件</summary>
|
||||
public TMP_Text[] LabelTexts { get; private set; }
|
||||
/// <summary>
|
||||
/// 维度标签的数量口径:<b>要几个就申请几个</b>,件本身由 chart 的文本槽位池发落
|
||||
/// (规范 §5.4:隐藏靠少申请,不靠把发落到的槽位 <c>SetActive(false)</c>——那会被校验当无效丢弃)。
|
||||
/// </summary>
|
||||
private int DesiredLabelCount
|
||||
=> ShowLabels && DimensionCount >= 3 ? DimensionCount : 0;
|
||||
|
||||
// ── 内部状态 ──────────────────────────────────────────────
|
||||
|
||||
@@ -114,11 +116,13 @@ namespace XericUI.XChart.Radar
|
||||
rt.offsetMin = Vector2.zero;
|
||||
rt.offsetMax = Vector2.zero;
|
||||
}
|
||||
}
|
||||
|
||||
// 创建标签父节点
|
||||
var labelsObj = CreateChild("Labels");
|
||||
LabelsRoot = labelsObj;
|
||||
|
||||
/// <summary>申请维度标签(只登记需求,件在 chart 的池调度里发落)</summary>
|
||||
public override void OnUpdate()
|
||||
{
|
||||
base.OnUpdate();
|
||||
RequestTextSlots(DesiredLabelCount);
|
||||
}
|
||||
|
||||
// ── 标记脏 ────────────────────────────────────────────────
|
||||
@@ -139,6 +143,8 @@ namespace XericUI.XChart.Radar
|
||||
DrawGrid();
|
||||
DrawAxis();
|
||||
UpdateLabels();
|
||||
// 槽位是下一轮调度才补齐的:还欠着件就保持脏,补齐后重画一次
|
||||
if (TextSlotsPending) m_DataDirty = true;
|
||||
}
|
||||
|
||||
// ── 网格绘制 ──────────────────────────────────────────────
|
||||
@@ -197,25 +203,18 @@ namespace XericUI.XChart.Radar
|
||||
|
||||
private void UpdateLabels()
|
||||
{
|
||||
if (LabelsRoot == null) return;
|
||||
|
||||
int dims = DimensionCount;
|
||||
var dirs = XChartRadarDataModel.GetDimensionDirections(dims);
|
||||
var labels = Texts;
|
||||
|
||||
// 确保标签数量匹配
|
||||
EnsureLabelCount(dims);
|
||||
// 件要下一轮调度才补齐:这一帧先画已有的那些,欠着的由 OnRender 保持脏后再画一遍
|
||||
int usable = Mathf.Min(dims, labels.Count);
|
||||
|
||||
bool show = ShowLabels && dims >= 3;
|
||||
|
||||
for (int i = 0; i < dims; i++)
|
||||
for (int i = 0; i < usable; i++)
|
||||
{
|
||||
var label = LabelTexts[i];
|
||||
var label = labels[i];
|
||||
if (label == null) continue;
|
||||
|
||||
label.gameObject.SetActive(show);
|
||||
|
||||
if (!show) continue;
|
||||
|
||||
// 设置文本
|
||||
string name = (i < DimensionNames.Length && DimensionNames[i] != null)
|
||||
? DimensionNames[i]
|
||||
@@ -239,65 +238,18 @@ namespace XericUI.XChart.Radar
|
||||
else
|
||||
label.alignment = TextAlignmentOptions.Top;
|
||||
|
||||
// 应用位置
|
||||
// 应用位置(尺寸也要在这里设:槽位来自池,创建时不知道要给哪个图表用)
|
||||
var rt = label.rectTransform;
|
||||
rt.anchoredPosition = labelPos;
|
||||
rt.anchorMin = new Vector2(0.5f, 0.5f);
|
||||
rt.anchorMax = new Vector2(0.5f, 0.5f);
|
||||
rt.pivot = new Vector2(0.5f, 0.5f);
|
||||
}
|
||||
|
||||
// 隐藏多余的标签
|
||||
for (int i = dims; i < LabelTexts.Length; i++)
|
||||
{
|
||||
if (LabelTexts[i] != null)
|
||||
LabelTexts[i].gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>确保标签数组长度匹配维度数量</summary>
|
||||
private void EnsureLabelCount(int count)
|
||||
{
|
||||
if (LabelTexts != null && LabelTexts.Length == count)
|
||||
return;
|
||||
|
||||
// 清理旧的标签
|
||||
if (LabelTexts != null)
|
||||
{
|
||||
foreach (var label in LabelTexts)
|
||||
{
|
||||
if (label != null && label.gameObject != null)
|
||||
{
|
||||
if (Application.isPlaying)
|
||||
Object.Destroy(label.gameObject);
|
||||
else
|
||||
Object.DestroyImmediate(label.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LabelTexts = new TMP_Text[count];
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var labelObj = new GameObject($"Label_{i}", typeof(RectTransform));
|
||||
labelObj.transform.SetParent(LabelsRoot, false);
|
||||
labelObj.hideFlags = CurrentFlags;
|
||||
|
||||
var tmp = labelObj.AddComponent<TextMeshProUGUI>();
|
||||
tmp.text = "";
|
||||
tmp.fontSize = LabelFontSize;
|
||||
tmp.color = LabelColor;
|
||||
tmp.alignment = TextAlignmentOptions.Center;
|
||||
|
||||
var rt = tmp.rectTransform;
|
||||
rt.anchorMin = new Vector2(0.5f, 0.5f);
|
||||
rt.anchorMax = new Vector2(0.5f, 0.5f);
|
||||
rt.pivot = new Vector2(0.5f, 0.5f);
|
||||
rt.sizeDelta = new Vector2(100f, 24f);
|
||||
|
||||
LabelTexts[i] = tmp;
|
||||
}
|
||||
|
||||
// 没点亮的槽位必须擦空:池件是跨维度数复用的,留着上一轮的字就是残影
|
||||
for (int i = usable; i < labels.Count; i++)
|
||||
if (labels[i] != null) labels[i].text = string.Empty;
|
||||
}
|
||||
|
||||
// ── 清理 ──────────────────────────────────────────────────
|
||||
@@ -306,8 +258,6 @@ namespace XericUI.XChart.Radar
|
||||
{
|
||||
GridRenderer = null;
|
||||
AxisRenderer = null;
|
||||
LabelsRoot = null;
|
||||
LabelTexts = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using UnityEngine;
|
||||
using XericLibrary.Runtime.UIGraph;
|
||||
using XericUI.Core;
|
||||
|
||||
namespace XericUI.XChart.Radar
|
||||
{
|
||||
@@ -14,7 +15,7 @@ namespace XericUI.XChart.Radar
|
||||
/// [ChartTool_RadarData]
|
||||
/// └─ DataRenderer (UILineRendererV2) — 所有数据系列的线框
|
||||
/// </summary>
|
||||
[AddComponentMenu("Xeric/XChart/Radar/Radar Data Tool")]
|
||||
[AddComponentMenu(XericRegistrationPaths.Chart + "/Radar/Radar Data Tool")]
|
||||
public class ChartToolRadarData : XChartToolBase
|
||||
{
|
||||
// ── 配置 ──────────────────────────────────────────────────
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using UnityEngine;
|
||||
using XericUI.Core;
|
||||
|
||||
namespace XericUI.XChart.Radar
|
||||
{
|
||||
@@ -27,7 +28,7 @@ namespace XericUI.XChart.Radar
|
||||
/// └─ [ChartTool_RadarData] (OrderIndex=10) ← 数据线框
|
||||
/// └─ DataRenderer (UILineRendererV2)
|
||||
/// </summary>
|
||||
[AddComponentMenu("Xeric/XChart/Radar/Radar Chart")]
|
||||
[AddComponentMenu(XericRegistrationPaths.Chart + "/Radar/Radar Chart")]
|
||||
[ExecuteAlways]
|
||||
public class XRadarChart : XChartBase
|
||||
{
|
||||
@@ -345,13 +346,19 @@ namespace XericUI.XChart.Radar
|
||||
|
||||
// ── 编辑器 ────────────────────────────────────────────────
|
||||
|
||||
#if UNITY_EDITOR
|
||||
private void OnValidate()
|
||||
/// <summary>
|
||||
/// override 基类并调 base:写成 <c>private void OnValidate()</c> 会遮掉基类那份,
|
||||
/// "重灌元素 + 强制刷新"就再也不会为这个组件执行(和散点图同一个坑)。
|
||||
/// </summary>
|
||||
protected override void OnValidate()
|
||||
{
|
||||
if (m_Radius < 10f) m_Radius = 10f;
|
||||
if (m_RingCount < 1) m_RingCount = 1;
|
||||
if (m_LabelFontSize < 4f) m_LabelFontSize = 4f;
|
||||
|
||||
base.OnValidate();
|
||||
|
||||
#if UNITY_EDITOR
|
||||
if (isActiveAndEnabled && m_RadarBg != null)
|
||||
{
|
||||
UnityEditor.EditorApplication.delayCall += () =>
|
||||
@@ -363,7 +370,7 @@ namespace XericUI.XChart.Radar
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user