feat(chapter): 添加章节图可视化编辑器

基于 UIToolkit 实现 ChapterGraph 编辑器窗口,可视化查看
和编辑 TalkSceneSO 之间的多出口连接关系。
This commit is contained in:
2026-04-25 20:13:55 +08:00
parent 93012f5f7c
commit 94d89330dc
11 changed files with 1217 additions and 0 deletions
@@ -0,0 +1,70 @@
using AibisDream;
using UnityEditor;
using UnityEngine;
namespace AibisDream.SystemEditor
{
public class ChapterGraphInspector
{
private Editor _editor;
private TalkSceneSO _target;
private Vector2 _scrollPosition;
public event System.Action<TalkSceneSO> OnColorChanged;
public void SetTarget(TalkSceneSO so)
{
// 不能用 ==,Unity 重载了 ==,已销毁的对象 == null 为 true
if (ReferenceEquals(_target, so)) return;
_target = so;
if (_editor != null)
{
Object.DestroyImmediate(_editor);
_editor = null;
}
if (so != null)
{
_editor = Editor.CreateEditor(so);
}
}
public void OnGUI()
{
if (_editor == null)
{
EditorGUILayout.HelpBox("请在图中选中一个章节节点以编辑属性", MessageType.Info);
return;
}
_scrollPosition = EditorGUILayout.BeginScrollView(_scrollPosition);
EditorGUI.BeginChangeCheck();
var newColor = EditorGUILayout.ColorField("节点颜色", _target.nodeColor);
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(_target, "Change Node Color");
_target.nodeColor = newColor;
EditorUtility.SetDirty(_target);
OnColorChanged?.Invoke(_target);
}
EditorGUILayout.Space(6);
_editor.OnInspectorGUI();
EditorGUILayout.EndScrollView();
}
public void Destroy()
{
if (_editor != null)
{
Object.DestroyImmediate(_editor);
_editor = null;
}
_target = null;
}
}
}