mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-21 09:46:03 +08:00
Merge pull request #219 from LumosX/global-drawers
Generic "Edit graph" button for node and graph inspectors
This commit is contained in:
commit
b1a9d7dcfa
48
Scripts/Editor/GraphAndNodeEditor.cs
Normal file
48
Scripts/Editor/GraphAndNodeEditor.cs
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Reflection;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace XNodeEditor {
|
||||||
|
/// <summary> Override graph inspector to show an 'Open Graph' button at the top </summary>
|
||||||
|
[CustomEditor(typeof(XNode.NodeGraph), true)]
|
||||||
|
public class GlobalGraphEditor : Editor {
|
||||||
|
public override void OnInspectorGUI() {
|
||||||
|
serializedObject.Update();
|
||||||
|
|
||||||
|
if (GUILayout.Button("Edit graph", GUILayout.Height(40))) {
|
||||||
|
NodeEditorWindow.Open(serializedObject.targetObject as XNode.NodeGraph);
|
||||||
|
}
|
||||||
|
|
||||||
|
GUILayout.Space(EditorGUIUtility.singleLineHeight);
|
||||||
|
GUILayout.Label("Raw data", "BoldLabel");
|
||||||
|
|
||||||
|
DrawDefaultInspector();
|
||||||
|
|
||||||
|
serializedObject.ApplyModifiedProperties();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[CustomEditor(typeof(XNode.Node), true)]
|
||||||
|
public class GlobalNodeEditor : Editor {
|
||||||
|
public override void OnInspectorGUI() {
|
||||||
|
serializedObject.Update();
|
||||||
|
|
||||||
|
if (GUILayout.Button("Edit graph", GUILayout.Height(40))) {
|
||||||
|
SerializedProperty graphProp = serializedObject.FindProperty("graph");
|
||||||
|
NodeEditorWindow w = NodeEditorWindow.Open(graphProp.objectReferenceValue as XNode.NodeGraph);
|
||||||
|
w.Home(); // Focus selected node
|
||||||
|
}
|
||||||
|
|
||||||
|
GUILayout.Space(EditorGUIUtility.singleLineHeight);
|
||||||
|
GUILayout.Label("Raw data", "BoldLabel");
|
||||||
|
|
||||||
|
// Now draw the node itself.
|
||||||
|
DrawDefaultInspector();
|
||||||
|
|
||||||
|
serializedObject.ApplyModifiedProperties();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Scripts/Editor/GraphAndNodeEditor.cs.meta
Normal file
11
Scripts/Editor/GraphAndNodeEditor.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: bdd6e443125ccac4dad0665515759637
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -187,12 +187,13 @@ namespace XNodeEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Open the provided graph in the NodeEditor</summary>
|
/// <summary>Open the provided graph in the NodeEditor</summary>
|
||||||
public static void Open(XNode.NodeGraph graph) {
|
public static NodeEditorWindow Open(XNode.NodeGraph graph) {
|
||||||
if (!graph) return;
|
if (!graph) return null;
|
||||||
|
|
||||||
NodeEditorWindow w = GetWindow(typeof(NodeEditorWindow), false, "xNode", true) as NodeEditorWindow;
|
NodeEditorWindow w = GetWindow(typeof(NodeEditorWindow), false, "xNode", true) as NodeEditorWindow;
|
||||||
w.wantsMouseMove = true;
|
w.wantsMouseMove = true;
|
||||||
w.graph = graph;
|
w.graph = graph;
|
||||||
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Repaint all open NodeEditorWindows. </summary>
|
/// <summary> Repaint all open NodeEditorWindows. </summary>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user