diff --git a/Example/ExampleNodeGraph.asset b/Example/ExampleNodeGraph.asset index 7b03462..aa70b38 100644 Binary files a/Example/ExampleNodeGraph.asset and b/Example/ExampleNodeGraph.asset differ diff --git a/Example/Nodes/DisplayValue.cs b/Example/Nodes/DisplayValue.cs index ef82b56..d19dd21 100644 --- a/Example/Nodes/DisplayValue.cs +++ b/Example/Nodes/DisplayValue.cs @@ -1,6 +1,6 @@ using UnityEngine; public class DisplayValue : ExampleNodeBase { - [Input(false)] public float value; + [Input] public float value; } diff --git a/Example/Nodes/MathNode.cs b/Example/Nodes/MathNode.cs index fef8659..374931d 100644 --- a/Example/Nodes/MathNode.cs +++ b/Example/Nodes/MathNode.cs @@ -2,9 +2,9 @@ [System.Serializable] public class MathNode : ExampleNodeBase { - [Input(true)] public float a; - [Input(true)] public float b; - [Output(false)] public float result; + [Input] public float a; + [Input] public float b; + [Output] public float result; public enum MathType { Add, Subtract, Multiply, Divide} public MathType mathType = MathType.Add; diff --git a/Example/Nodes/TestNode.cs b/Example/Nodes/TestNode.cs index e16136d..dd5b44b 100644 --- a/Example/Nodes/TestNode.cs +++ b/Example/Nodes/TestNode.cs @@ -5,14 +5,14 @@ using UnityEngine; public class TestNode : Node { public int myInt; - [Input(false)] public float myFloat; + [Input] public float myFloat; public double myDouble; public long myLong; public bool myBool; - [Input(true)] public string myString; + [Input] public string myString; public Rect myRect; - [Input(true)] public Vector2 myVec2; - [Input(true)] public Vector3 myVec3; + [Input] public Vector2 myVec2; + [Input] public Vector3 myVec3; public Vector4 myVec4; public Color myColor; public AnimationCurve myCurve; diff --git a/Scripts/Editor/NodeEditor.cs b/Scripts/Editor/NodeEditor.cs index cdba07d..4cc842a 100644 --- a/Scripts/Editor/NodeEditor.cs +++ b/Scripts/Editor/NodeEditor.cs @@ -31,7 +31,6 @@ public class NodeEditor { 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 == "position") continue; NodeEditorGUILayout.PropertyField(target, fields[i], portPositions); } diff --git a/Scripts/Editor/NodeEditorGUI.cs b/Scripts/Editor/NodeEditorGUI.cs index 728b2e3..8816e86 100644 --- a/Scripts/Editor/NodeEditorGUI.cs +++ b/Scripts/Editor/NodeEditorGUI.cs @@ -108,10 +108,7 @@ public partial class NodeEditorWindow { if (startPoint.x > endPoint.x) endTangent.x = Mathf.LerpUnclamped(endPoint.x, startPoint.x, -0.7f); else endTangent.x = Mathf.LerpUnclamped(endPoint.x, startPoint.x, 0.7f); - Color prevCol = GUI.color; - Color edgeCol = new Color(0.1f, 0.1f, 0.1f, col.a); Handles.DrawBezier(startPoint, endPoint, startTangent, endTangent, col, null, 4); - GUI.color = prevCol; } /// Draws all connections diff --git a/Scripts/Editor/NodeEditorGUILayout.cs b/Scripts/Editor/NodeEditorGUILayout.cs index 8af369f..bdee6c0 100644 --- a/Scripts/Editor/NodeEditorGUILayout.cs +++ b/Scripts/Editor/NodeEditorGUILayout.cs @@ -50,12 +50,13 @@ public class NodeEditorGUILayout { if (NodeEditorUtilities.GetAttrib(fieldAttribs, out inputAttrib)) { NodePort port = target.GetPortByFieldName(fieldName); Vector2 portPos; - fieldValue = PortField(fieldPrettyName, fieldValue, fieldType, port, inputAttrib.fallback, out portPos); + bool fallback = inputAttrib.backingValue == Node.ShowBackingValue.Always || (inputAttrib.backingValue == Node.ShowBackingValue.Unconnected && !port.IsConnected); + fieldValue = PortField(fieldPrettyName, fieldValue, fieldType, port, 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, fieldType, port, outputAttrib.fallback, out portPos); + fieldValue = PortField(fieldPrettyName, fieldValue, fieldType, port, false, out portPos); portPositions.Add(port, portPos); } else { fieldValue = PropertyField(fieldPrettyName, fieldValue, fieldType); diff --git a/Scripts/Node.cs b/Scripts/Node.cs index a604df4..3f3c083 100644 --- a/Scripts/Node.cs +++ b/Scripts/Node.cs @@ -7,7 +7,14 @@ using UnityEngine; /// Base class for all nodes [Serializable] public abstract class Node : ScriptableObject { - public enum ShowBackingValue { Never, Unconnected, Always } + public enum ShowBackingValue { + /// Never show the backing value + Never, + /// Show the backing value only when the port does not have any active connections + Unconnected, + /// Always show the backing value + Always + } /// Name of the node [SerializeField] public NodeGraph graph; @@ -21,7 +28,7 @@ public abstract class Node : ScriptableObject { public int OutputCount { get { return outputs.Count; } } protected void OnEnable() { - GetPorts(); + NodeDataCache.UpdatePorts(this, inputs, outputs); Init(); } @@ -98,19 +105,20 @@ public abstract class Node : ScriptableObject { return JsonUtility.ToJson(this).GetHashCode(); } + /// Mark a serializable field as an input port. You can access this through [AttributeUsage(AttributeTargets.Field, AllowMultiple = true)] public class InputAttribute : Attribute { public ShowBackingValue backingValue; + + /// Mark a serializable field as an input port. You can access this through + /// Should we display the backing value for this port as an editor field? public InputAttribute(ShowBackingValue backingValue = ShowBackingValue.Unconnected) { this.backingValue = backingValue; } } + /// Mark a serializable field as an output port. You can access this through [AttributeUsage(AttributeTargets.Field, AllowMultiple = true)] public class OutputAttribute : Attribute { - public bool fallback; - public OutputAttribute(bool fallback) { this.fallback = fallback; } - } - - private void GetPorts() { - NodeDataCache.UpdatePorts(this, inputs, outputs); + /// Mark a serializable field as an output port. You can access this through + public OutputAttribute() { } } } \ No newline at end of file