mirror of
https://github.com/Siccity/xNode.git
synced 2026-03-26 22:49:02 +08:00
Added Odin Inspector support
This commit is contained in:
parent
80c8b36ab8
commit
81b0c98f8d
@ -27,16 +27,35 @@ namespace XNodeEditor {
|
|||||||
serializedObject.Update();
|
serializedObject.Update();
|
||||||
string[] excludes = { "m_Script", "graph", "position", "ports" };
|
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)
|
// Iterate through serialized properties and draw them like the Inspector (But with ports)
|
||||||
SerializedProperty iterator = serializedObject.GetIterator();
|
SerializedProperty iterator = serializedObject.GetIterator();
|
||||||
bool enterChildren = true;
|
bool enterChildren = true;
|
||||||
EditorGUIUtility.labelWidth = 84;
|
EditorGUIUtility.labelWidth = 84;
|
||||||
while (iterator.NextVisible(enterChildren)) {
|
while (iterator.NextVisible(enterChildren)) {
|
||||||
enterChildren = false;
|
enterChildren = false;
|
||||||
|
#if ODIN_INSPECTOR
|
||||||
|
if (drawnbyXNode.Contains(iterator.name)) NodeEditorGUILayout.PropertyField(iterator, true);
|
||||||
|
#else
|
||||||
if (excludes.Contains(iterator.name)) continue;
|
if (excludes.Contains(iterator.name)) continue;
|
||||||
NodeEditorGUILayout.PropertyField(iterator, true);
|
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
|
// Iterate through dynamic ports and draw them in the order in which they are serialized
|
||||||
foreach (XNode.NodePort dynamicPort in target.DynamicPorts) {
|
foreach (XNode.NodePort dynamicPort in target.DynamicPorts) {
|
||||||
if (NodeEditorGUILayout.IsDynamicPortListPort(dynamicPort)) continue;
|
if (NodeEditorGUILayout.IsDynamicPortListPort(dynamicPort)) continue;
|
||||||
@ -44,6 +63,15 @@ namespace XNodeEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
serializedObject.ApplyModifiedProperties();
|
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() {
|
public virtual int GetWidth() {
|
||||||
|
|||||||
@ -17,6 +17,21 @@ namespace XNodeEditor.Internal {
|
|||||||
public NodeEditorWindow window;
|
public NodeEditorWindow window;
|
||||||
public K target;
|
public K target;
|
||||||
public SerializedObject serializedObject;
|
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) {
|
public static T GetEditor(K target, NodeEditorWindow window) {
|
||||||
if (target == null) return null;
|
if (target == null) return null;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user