71 lines
1.9 KiB
C#
71 lines
1.9 KiB
C#
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;
|
|
}
|
|
}
|
|
}
|