diff --git a/Scripts/Editor/NodeEditor.cs b/Scripts/Editor/NodeEditor.cs index 631d8e5..91b4b54 100644 --- a/Scripts/Editor/NodeEditor.cs +++ b/Scripts/Editor/NodeEditor.cs @@ -10,7 +10,7 @@ namespace XNodeEditor { public class NodeEditor : XNodeEditor.Internal.NodeEditorBase { private readonly Color DEFAULTCOLOR = new Color32(90, 97, 105, 255); - + /// Fires every whenever a node was modified through the editor public static Action onUpdateNode; public readonly static Dictionary portPositions = new Dictionary(); @@ -27,16 +27,35 @@ namespace XNodeEditor { serializedObject.Update(); string[] excludes = { "m_Script", "graph", "position", "ports" }; +#if ODIN_INSPECTOR + // let xNode handle these + string[] drawnbyXNode = { "input", "output" }; +#endif + // Iterate through serialized properties and draw them like the Inspector (But with ports) SerializedProperty iterator = serializedObject.GetIterator(); bool enterChildren = true; EditorGUIUtility.labelWidth = 84; while (iterator.NextVisible(enterChildren)) { enterChildren = false; +#if ODIN_INSPECTOR + if (drawnbyXNode.Contains(iterator.name)) NodeEditorGUILayout.PropertyField(iterator, true); +#else if (excludes.Contains(iterator.name)) continue; NodeEditorGUILayout.PropertyField(iterator, true); +#endif } +#if ODIN_INSPECTOR + InspectorUtilities.BeginDrawPropertyTree(objectTree, true); + objectTree.EnumerateTree(includeChildren: false).ForEach(p => { + if (!drawnbyXNode.Contains(p.Name) && !excludes.Contains(p.Name)) { + p.Draw(); + } + }); + InspectorUtilities.EndDrawPropertyTree(objectTree); +#endif + // Iterate through dynamic ports and draw them in the order in which they are serialized foreach (XNode.NodePort dynamicPort in target.DynamicPorts) { if (NodeEditorGUILayout.IsDynamicPortListPort(dynamicPort)) continue; @@ -44,6 +63,15 @@ namespace XNodeEditor { } serializedObject.ApplyModifiedProperties(); + +#if ODIN_INSPECTOR + // Call repaint so that the graph window elements respond properly to layout changes coming from Odin + if (GUIHelper.RepaintRequested) { + GUIHelper.ClearRepaintRequest(); + } +#else + window.Repaint(); +#endif } public virtual int GetWidth() { diff --git a/Scripts/Editor/NodeEditorBase.cs b/Scripts/Editor/NodeEditorBase.cs index 261a284..8695882 100644 --- a/Scripts/Editor/NodeEditorBase.cs +++ b/Scripts/Editor/NodeEditorBase.cs @@ -17,6 +17,21 @@ namespace XNodeEditor.Internal { public NodeEditorWindow window; public K target; public SerializedObject serializedObject; +#if ODIN_INSPECTOR + private PropertyTree _objectTree; + public PropertyTree objectTree { + get { + if (this._objectTree == null) { + try { + this._objectTree = PropertyTree.Create(this.serializedObject); + } catch (ArgumentException ex) { + Debug.Log(ex); + } + } + return this._objectTree; + } + } +#endif public static T GetEditor(K target, NodeEditorWindow window) { if (target == null) return null;