Added defualt graph properties inspector;
Added sticky note; Changed the name of BaseNode to SlotContainerNode in case we need other type of nodes in the future;
This commit is contained in:
109
Editor/Views/GraphObject/GraphObjectEditor.cs
Normal file
109
Editor/Views/GraphObject/GraphObjectEditor.cs
Normal file
@@ -0,0 +1,109 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Callbacks;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace Misaki.GraphView.Editor
|
||||
{
|
||||
[CustomEditor(typeof(GraphObject))]
|
||||
public class GraphObjectEditor : UnityEditor.Editor
|
||||
{
|
||||
private readonly Dictionary<string, List<SerializedProperty>> _inspectorPropertyMap = new ();
|
||||
|
||||
private GraphObject _graphObject;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_graphObject = target as GraphObject;
|
||||
|
||||
if (_graphObject == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GetSerializedProperty();
|
||||
}
|
||||
|
||||
protected virtual void GetSerializedProperty()
|
||||
{
|
||||
foreach (var property in _graphObject.ExposedProperties)
|
||||
{
|
||||
var showInInspectorField = property.GetType().GetField(nameof(ExposedProperty.showInInspector));
|
||||
if (showInInspectorField == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var showInInspectorValue = showInInspectorField.GetValue(property);
|
||||
if (showInInspectorValue is not bool or bool and false)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var fields = property.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
|
||||
var i = _graphObject.ExposedProperties.IndexOf(property);
|
||||
foreach (var field in fields)
|
||||
{
|
||||
var serializedProperty = serializedObject.FindProperty("_exposedProperties")?.GetArrayElementAtIndex(i)?.FindPropertyRelative(field.Name);
|
||||
if (serializedProperty == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!_inspectorPropertyMap.ContainsKey(property.propertyName))
|
||||
{
|
||||
_inspectorPropertyMap[property.propertyName] = new ();
|
||||
}
|
||||
|
||||
_inspectorPropertyMap[property.propertyName].Add(serializedProperty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual VisualElement CreateInspectorProperty()
|
||||
{
|
||||
var graphPropertyFoldout = new Foldout()
|
||||
{
|
||||
text = "Graph Properties",
|
||||
value = true
|
||||
};
|
||||
|
||||
foreach (var property in _inspectorPropertyMap)
|
||||
{
|
||||
var label = new Label(property.Key)
|
||||
{
|
||||
style =
|
||||
{
|
||||
unityFontStyleAndWeight = FontStyle.Bold,
|
||||
marginTop = 4,
|
||||
marginBottom = 2,
|
||||
}
|
||||
};
|
||||
|
||||
var propertyContainer = new VisualElement()
|
||||
{
|
||||
style =
|
||||
{
|
||||
marginLeft = 15
|
||||
}
|
||||
};
|
||||
|
||||
foreach (var serializedProperty in property.Value)
|
||||
{
|
||||
var inputField = new PropertyField(serializedProperty);
|
||||
inputField.Bind(serializedObject);
|
||||
propertyContainer.Add(inputField);
|
||||
}
|
||||
|
||||
graphPropertyFoldout.Add(label);
|
||||
graphPropertyFoldout.Add(propertyContainer);
|
||||
}
|
||||
|
||||
return graphPropertyFoldout;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Editor/Views/GraphObject/GraphObjectEditor.cs.meta
Normal file
3
Editor/Views/GraphObject/GraphObjectEditor.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 032ca62a690e4cb4be9c91fe2f4a955a
|
||||
timeCreated: 1730603608
|
||||
Reference in New Issue
Block a user