1
0
mirror of https://github.com/Siccity/xNode.git synced 2026-02-11 17:48:46 +08:00

Updated README.md

This commit is contained in:
Thor Brigsted 2017-10-28 00:06:34 +02:00
parent 3e91a30e88
commit e42622bcf6

View File

@ -22,24 +22,34 @@ With a minimal footprint, UNEC is ideal as a base for custom state machines, dia
```csharp ```csharp
[System.Serializable] [System.Serializable]
public class MathNode : Node { 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 a;
[Input] public float b; [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; [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 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) { public override object GetValue(NodePort port) {
if (port.fieldName == "result") {
float a = GetInputFloat("a"); // Get new a and b values from input connections. Fallback to field values if input is not connected
float b = GetInputFloat("b"); float a = GetInputByFieldName<float>("a", this.a);
float b = GetInputByFieldName<float>("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) { switch(mathType) {
case MathType.Add: return a + b; case MathType.Add: default: return a + b;
case MathType.Subtract: return a - b; case MathType.Subtract: return a - b;
case MathType.Multiply: return a * b; case MathType.Multiply: return a * b;
case MathType.Divide: return a / b; case MathType.Divide: return a / b;
} }
} else if (port.fieldName == "sum") return a + b;
return 0f; else return 0f;
} }
} }
``` ```