diff --git a/Example/ExampleNodeGraph.asset b/Example/ExampleNodeGraph.asset index ca1eaae..01543d1 100644 --- a/Example/ExampleNodeGraph.asset +++ b/Example/ExampleNodeGraph.asset @@ -57,9 +57,9 @@ MonoBehaviour: node: {fileID: 114708853913061688} _direction: 1 _dynamic: 0 - a: 3.06 - b: 7.29 - result: 0 + a: 6.48 + b: 7.59 + result: 14.07 mathType: 0 --- !u!114 &114708853913061688 MonoBehaviour: @@ -116,7 +116,7 @@ MonoBehaviour: x: 0 y: 2.6412349 z: 14.33477 - vector: {x: 0, y: 0, z: 0} + vector: {x: 14.07, y: 2.6412349, z: 14.33477} --- !u!114 &114729867621534192 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Example/Nodes/MathNode.cs b/Example/Nodes/MathNode.cs index 25576b5..b94bbca 100644 --- a/Example/Nodes/MathNode.cs +++ b/Example/Nodes/MathNode.cs @@ -21,14 +21,15 @@ namespace BasicNodes { float b = GetInputValue("b", this.b); // After you've gotten your input values, you can perform your calculations and return a value + result = 0f; if (port.fieldName == "result") switch (mathType) { - case MathType.Add: default: return a + b; - case MathType.Subtract: return a - b; - case MathType.Multiply: return a * b; - case MathType.Divide: return a / b; + case MathType.Add: default: result = a+b; break; + case MathType.Subtract: result = a - b; break; + case MathType.Multiply: result = a * b; break; + case MathType.Divide: result = a / b; break; } - else return 0f; + return result; } } } \ No newline at end of file diff --git a/Example/Nodes/Vector.cs b/Example/Nodes/Vector.cs index b866283..4c729fb 100644 --- a/Example/Nodes/Vector.cs +++ b/Example/Nodes/Vector.cs @@ -7,10 +7,10 @@ namespace BasicNodes { [Output] public Vector3 vector; public override object GetValue(NodePort port) { - float x = GetInputValue("x", this.x); - float y = GetInputValue("y", this.y); - float z = GetInputValue("z", this.z); - return new Vector3(x, y, z); + vector.x = GetInputValue("x", this.x); + vector.y = GetInputValue("y", this.y); + vector.z = GetInputValue("z", this.z); + return vector; } } } \ No newline at end of file diff --git a/Scripts/Editor/NodeEditorGUI.cs b/Scripts/Editor/NodeEditorGUI.cs index 5523abd..39af285 100644 --- a/Scripts/Editor/NodeEditorGUI.cs +++ b/Scripts/Editor/NodeEditorGUI.cs @@ -243,6 +243,7 @@ namespace XNodeEditor { Type type = hoveredPort.ValueType; GUIContent content = new GUIContent(); content.text = TypeToString(type); + if (hoveredPort.IsStatic && hoveredPort.IsOutput) content.text += " = " + ObjectFromFieldName(hoveredPort.node, hoveredPort.fieldName).ToString(); Vector2 size = NodeEditorResources.styles.tooltip.CalcSize(content); Rect rect = new Rect(Event.current.mousePosition - (size), size); EditorGUI.LabelField(rect, content, NodeEditorResources.styles.tooltip); @@ -252,6 +253,7 @@ namespace XNodeEditor { private string TypeToString(Type type) { if (type == null) return "null"; + if (type == typeof(System.Object)) return "object"; if (type == typeof(float)) return "float"; else if (type == typeof(int)) return "int"; else if (type == typeof(long)) return "long"; diff --git a/Scripts/Editor/NodeEditorReflection.cs b/Scripts/Editor/NodeEditorReflection.cs index 316ef94..99448ae 100644 --- a/Scripts/Editor/NodeEditorReflection.cs +++ b/Scripts/Editor/NodeEditorReflection.cs @@ -48,5 +48,11 @@ namespace XNodeEditor { public static object ObjectFromType(Type type) { return Activator.CreateInstance(type); } + + public static object ObjectFromFieldName(object obj, string fieldName) { + Type type = obj.GetType(); + FieldInfo fieldInfo = type.GetField(fieldName); + return fieldInfo.GetValue(obj); + } } } \ No newline at end of file