From 81f01cefc9ae25308b3cd52f4ac9810d53b391c8 Mon Sep 17 00:00:00 2001 From: Thor Brigsted Date: Sun, 15 Oct 2017 16:31:46 +0200 Subject: [PATCH] Added editor callback onUpdateNode --- Scripts/Editor/NodeEditor.cs | 39 ++++++------------------------------ 1 file changed, 6 insertions(+), 33 deletions(-) diff --git a/Scripts/Editor/NodeEditor.cs b/Scripts/Editor/NodeEditor.cs index e1777eb..dce746c 100644 --- a/Scripts/Editor/NodeEditor.cs +++ b/Scripts/Editor/NodeEditor.cs @@ -7,7 +7,8 @@ using UnityEngine; /// Base class to derive custom Node editors from. Use this to create your own custom inspectors and editors for your nodes. public class NodeEditor { - + /// Fires every whenever a node was modified through the editor + public static Action onUpdateNode; public Node target; /// Draws the node GUI. @@ -26,45 +27,17 @@ public class NodeEditor { protected void DrawDefaultNodeBodyGUI(out Dictionary portPositions) { portPositions = new Dictionary(); + EditorGUI.BeginChangeCheck(); FieldInfo[] fields = GetInspectorFields(target); for (int i = 0; i < fields.Length; i++) { object[] fieldAttribs = fields[i].GetCustomAttributes(false); if (fields[i].Name == "graph" || fields[i].Name == "rect") continue; NodeEditorGUILayout.PropertyField(target, fields[i], portPositions); } - } - - /// Draw node port GUI using automatic layouting. Returns port handle position. - protected Vector2 DrawNodePortGUI(NodePort port) { - GUIStyle style = port.direction == NodePort.IO.Input ? NodeEditorResources.styles.inputPort : NodeEditorResources.styles.outputPort; - Rect rect = GUILayoutUtility.GetRect(new GUIContent(port.fieldName.PrettifyCamelCase()), style); - return DrawNodePortGUI(rect, port); - } - - /// Draw node port GUI in rect. Returns port handle position. - protected Vector2 DrawNodePortGUI(Rect rect, NodePort port) { - GUIStyle style = port.direction == NodePort.IO.Input ? NodeEditorResources.styles.inputPort : NodeEditorResources.styles.outputPort; - GUI.Label(rect, new GUIContent(port.fieldName.PrettifyCamelCase()), style); - - Vector2 handlePoint = rect.center; - - switch (port.direction) { - case NodePort.IO.Input: - handlePoint.x = rect.xMin; - break; - case NodePort.IO.Output: - handlePoint.x = rect.xMax; - break; + //If user changed a value, notify other scripts through onUpdateNode + if (EditorGUI.EndChangeCheck()) { + if (onUpdateNode != null) onUpdateNode(target); } - - Color col = GUI.color; - Rect handleRect = new Rect(handlePoint.x - 8, handlePoint.y - 8, 16, 16); - GUI.color = new Color32(90, 97, 105, 255); - GUI.DrawTexture(handleRect, NodeEditorResources.dotOuter); - GUI.color = NodeEditorPreferences.GetTypeColor(port.type); - GUI.DrawTexture(handleRect, NodeEditorResources.dot); - GUI.color = col; - return handlePoint; } private static FieldInfo[] GetInspectorFields(Node node) {