diff --git a/Example/ExampleNodeGraph.asset b/Example/ExampleNodeGraph.asset index b09f280..9650943 100644 Binary files a/Example/ExampleNodeGraph.asset and b/Example/ExampleNodeGraph.asset differ diff --git a/Example/Nodes/TestNode.cs b/Example/Nodes/TestNode.cs index 900ddf4..e16136d 100644 --- a/Example/Nodes/TestNode.cs +++ b/Example/Nodes/TestNode.cs @@ -4,16 +4,16 @@ using UnityEngine; public class TestNode : Node { - public int i; - public float f; - public double d; - public long l; - public bool b; - public string s; - public Rect r; - public Vector2 v2; - public Vector3 v3; - public Vector4 v4; - public Color col; - public AnimationCurve a; + public int myInt; + [Input(false)] public float myFloat; + public double myDouble; + public long myLong; + public bool myBool; + [Input(true)] public string myString; + public Rect myRect; + [Input(true)] public Vector2 myVec2; + [Input(true)] public Vector3 myVec3; + public Vector4 myVec4; + public Color myColor; + public AnimationCurve myCurve; } diff --git a/Scripts/Editor/NodeEditorGUI.cs b/Scripts/Editor/NodeEditorGUI.cs index cc7fca0..2dac4cb 100644 --- a/Scripts/Editor/NodeEditorGUI.cs +++ b/Scripts/Editor/NodeEditorGUI.cs @@ -15,6 +15,7 @@ public partial class NodeEditorWindow { DrawConnections(); DrawDraggedConnection(); DrawNodes(); + DrawTooltip(); GUI.matrix = m; } @@ -193,4 +194,14 @@ public partial class NodeEditorWindow { if (onValidate != null && nodeHash != selectedNode.GetHashCode()) onValidate.Invoke(selectedNode, null); } } + + private void DrawTooltip() { + if (hoveredPort != null) { + GUIContent content = new GUIContent(hoveredPort.type.ToString()); + Vector2 size = NodeEditorResources.styles.tooltip.CalcSize(content); + Rect rect = new Rect(Event.current.mousePosition - (size), size); + EditorGUI.LabelField(rect, content, NodeEditorResources.styles.tooltip); + Repaint(); + } + } } \ No newline at end of file diff --git a/Scripts/Editor/NodeEditorGUILayout.cs b/Scripts/Editor/NodeEditorGUILayout.cs index 9683c70..522f352 100644 --- a/Scripts/Editor/NodeEditorGUILayout.cs +++ b/Scripts/Editor/NodeEditorGUILayout.cs @@ -11,8 +11,8 @@ public class NodeEditorGUILayout { private static double tempValue; - public static object PortField(string label, object value, NodePort port, bool fallback, out Vector2 portPosition) { - if (fallback) value = PropertyField(label, value); + public static object PortField(string label, object value, System.Type type, NodePort port, bool fallback, out Vector2 portPosition) { + if (fallback) value = PropertyField(label, value, type); else EditorGUILayout.LabelField(label); Rect rect = GUILayoutUtility.GetLastRect(); @@ -50,15 +50,15 @@ public class NodeEditorGUILayout { if (NodeEditorUtilities.GetAttrib(fieldAttribs, out inputAttrib)) { NodePort port = target.GetPortByFieldName(fieldName); Vector2 portPos; - fieldValue = PortField(fieldPrettyName, fieldValue, port, inputAttrib.fallback, out portPos); + fieldValue = PortField(fieldPrettyName, fieldValue, fieldType, port, inputAttrib.fallback, out portPos); portPositions.Add(port, portPos); } else if (NodeEditorUtilities.GetAttrib(fieldAttribs, out outputAttrib)) { NodePort port = target.GetPortByFieldName(fieldName); Vector2 portPos; - fieldValue = PortField(fieldPrettyName, fieldValue, port, outputAttrib.fallback, out portPos); + fieldValue = PortField(fieldPrettyName, fieldValue, fieldType, port, outputAttrib.fallback, out portPos); portPositions.Add(port, portPos); } else { - fieldValue = PropertyField(fieldPrettyName, fieldValue); + fieldValue = PropertyField(fieldPrettyName, fieldValue, fieldType); } if (EditorGUI.EndChangeCheck()) { @@ -68,7 +68,7 @@ public class NodeEditorGUILayout { return fieldValue; } - public static object PropertyField(string label, object value) { + public static object PropertyField(string label, object value, System.Type type) { if (value is int) return IntField(label, (int) value); else if (value is float) return FloatField(label, (float) value); else if (value is double) return DoubleField(label, (double) value); @@ -82,7 +82,7 @@ public class NodeEditorGUILayout { else if (value is Vector4) return Vector4Field(label, (Vector4) value); else if (value is Color) return ColorField(label, (Color) value); else if (value is AnimationCurve) return CurveField(label, (AnimationCurve) value); - else if (value == null || value.GetType().IsSubclassOf(typeof(UnityEngine.Object)) || value.GetType() == typeof(UnityEngine.Object)) return ObjectField(label, (UnityEngine.Object) value); + else if (type.IsSubclassOf(typeof(UnityEngine.Object)) || type == typeof(UnityEngine.Object)) return ObjectField(label, (UnityEngine.Object) value); else return value; } public static Rect GetRect(string label) { diff --git a/Scripts/Editor/NodeEditorResources.cs b/Scripts/Editor/NodeEditorResources.cs index 7ec60ad..70853e6 100644 --- a/Scripts/Editor/NodeEditorResources.cs +++ b/Scripts/Editor/NodeEditorResources.cs @@ -26,7 +26,7 @@ public static class NodeEditorResources { public static Styles _styles = null; public class Styles { - public GUIStyle inputPort, outputPort, nodeHeader, nodeBody; + public GUIStyle inputPort, outputPort, nodeHeader, nodeBody, tooltip; public Styles() { GUIStyle baseStyle = new GUIStyle("Label"); @@ -49,6 +49,12 @@ public static class NodeEditorResources { nodeBody.normal.background = NodeEditorResources.nodeBody; nodeBody.border = new RectOffset(32, 32, 32, 32); nodeBody.padding = new RectOffset(16, 16, 4, 6); + + tooltip = new GUIStyle("helpBox"); + tooltip.alignment = TextAnchor.MiddleCenter; + //tooltip.border = new RectOffset(0, 0, 0, 0); + //tooltip.normal.background + //tooltip.padding = new RectOffset(0, 0, 0, 0); } }