IndieGame/client/Assets/Ether/Editor/Extension/InspectorViewer.cs

43 lines
1.3 KiB
C#
Raw Permalink Normal View History

2024-10-11 10:12:15 +08:00

using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
namespace Ether
{
public class InspectorViewer : VisualElement
{
public new class UxmlFactory : UxmlFactory<InspectorViewer, VisualElement.UxmlTraits> { }
Editor editor;
internal void UpdateSelection(EtherNodeView nodeView)
{
Clear();
Object.DestroyImmediate(editor);
editor = Editor.CreateEditor(nodeView.node);
IMGUIContainer container = new IMGUIContainer(() =>
{
if (nodeView.node && editor.target)
{
// 使用 BeginGUI 和 EndGUI 来包裹 OnInspectorGUI 调用
EditorGUILayout.BeginVertical();
editor.OnInspectorGUI();
EditorGUILayout.EndVertical();
// 检查是否点击了 Inspector 区域
if (Event.current.type == EventType.MouseDown &&
GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition))
{
Event.current.Use(); // 标记事件已被使用,阻止冒泡
}
}
});
Add(container);
}
}
}