diff --git a/README.md b/README.md index 72ace39..a9392c6 100644 --- a/README.md +++ b/README.md @@ -22,24 +22,34 @@ With a minimal footprint, UNEC is ideal as a base for custom state machines, dia ```csharp [System.Serializable] public class MathNode : Node { + // Adding [Input] or [Output] is all you need to do to register a field as a valid port on your node [Input] public float a; [Input] public float b; + // The value of an output node field is not used for anything, but could be used for caching output results [Output] public float result; - public enum MathType { Add, Subtract, Multiply, Divide} + [Output] public float sum; + + // UNEC will display this as an editable field - just like the normal inspector would public MathType mathType = MathType.Add; + public enum MathType { Add, Subtract, Multiply, Divide} + // GetValue should be overridden to return a value for any specified output port public override object GetValue(NodePort port) { - if (port.fieldName == "result") { - float a = GetInputFloat("a"); - float b = GetInputFloat("b"); + + // Get new a and b values from input connections. Fallback to field values if input is not connected + float a = GetInputByFieldName("a", this.a); + float b = GetInputByFieldName("b", this.b); + + // After you've gotten your input values, you can perform your calculations and return a value + if (port.fieldName == "result") switch(mathType) { - case MathType.Add: return a + b; + 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; } - } - return 0f; + else if (port.fieldName == "sum") return a + b; + else return 0f; } } ```