summaryrefslogtreecommitdiff
path: root/Other/NodeEditorExamples/Assets/xNode-examples/Scripts/Editor/SceneGraphEditor.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2022-06-28 09:40:37 +0800
committerchai <chaifix@163.com>2022-06-28 09:40:37 +0800
commit49b25e755b70ec412feaaf0b898d6f7e09d2bea6 (patch)
tree3c5f4260f30d1c2d7196db93153700d7ddec3157 /Other/NodeEditorExamples/Assets/xNode-examples/Scripts/Editor/SceneGraphEditor.cs
parentc92269331692feca2c276649f6c4ee8911f1f859 (diff)
+node example
Diffstat (limited to 'Other/NodeEditorExamples/Assets/xNode-examples/Scripts/Editor/SceneGraphEditor.cs')
-rw-r--r--Other/NodeEditorExamples/Assets/xNode-examples/Scripts/Editor/SceneGraphEditor.cs77
1 files changed, 77 insertions, 0 deletions
diff --git a/Other/NodeEditorExamples/Assets/xNode-examples/Scripts/Editor/SceneGraphEditor.cs b/Other/NodeEditorExamples/Assets/xNode-examples/Scripts/Editor/SceneGraphEditor.cs
new file mode 100644
index 00000000..9fb1c673
--- /dev/null
+++ b/Other/NodeEditorExamples/Assets/xNode-examples/Scripts/Editor/SceneGraphEditor.cs
@@ -0,0 +1,77 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using UnityEditor;
+using UnityEngine;
+using XNode;
+
+namespace XNodeEditor {
+ [CustomEditor(typeof(SceneGraph), true)]
+ public class SceneGraphEditor : Editor {
+ private SceneGraph sceneGraph;
+ private bool removeSafely;
+ private Type graphType;
+
+ public override void OnInspectorGUI() {
+ if (sceneGraph.graph == null) {
+ if (GUILayout.Button("New graph", GUILayout.Height(40))) {
+ if (graphType == null) {
+ Type[] graphTypes = NodeEditorReflection.GetDerivedTypes(typeof(NodeGraph));
+ GenericMenu menu = new GenericMenu();
+ for (int i = 0; i < graphTypes.Length; i++) {
+ Type graphType = graphTypes[i];
+ menu.AddItem(new GUIContent(graphType.Name), false, () => CreateGraph(graphType));
+ }
+ menu.ShowAsContext();
+ } else {
+ CreateGraph(graphType);
+ }
+ }
+ } else {
+ if (GUILayout.Button("Open graph", GUILayout.Height(40))) {
+ NodeEditorWindow.Open(sceneGraph.graph);
+ }
+ if (removeSafely) {
+ GUILayout.BeginHorizontal();
+ GUILayout.Label("Really remove graph?");
+ GUI.color = new Color(1, 0.8f, 0.8f);
+ if (GUILayout.Button("Remove")) {
+ removeSafely = false;
+ Undo.RecordObject(sceneGraph, "Removed graph");
+ sceneGraph.graph = null;
+ }
+ GUI.color = Color.white;
+ if (GUILayout.Button("Cancel")) {
+ removeSafely = false;
+ }
+ GUILayout.EndHorizontal();
+ } else {
+ GUI.color = new Color(1, 0.8f, 0.8f);
+ if (GUILayout.Button("Remove graph")) {
+ removeSafely = true;
+ }
+ GUI.color = Color.white;
+ }
+ }
+ }
+
+ private void OnEnable() {
+ sceneGraph = target as SceneGraph;
+ Type sceneGraphType = sceneGraph.GetType();
+ if (sceneGraphType == typeof(SceneGraph)) {
+ graphType = null;
+ } else {
+ Type baseType = sceneGraphType.BaseType;
+ if (baseType.IsGenericType) {
+ graphType = sceneGraphType = baseType.GetGenericArguments() [0];
+ }
+ }
+ }
+
+ public void CreateGraph(Type type) {
+ Undo.RecordObject(sceneGraph, "Create graph");
+ sceneGraph.graph = ScriptableObject.CreateInstance(type) as NodeGraph;
+ sceneGraph.graph.name = sceneGraph.name + "-graph";
+ }
+ }
+} \ No newline at end of file