mirror of
https://github.com/Siccity/xNode.git
synced 2026-02-06 15:24:55 +08:00
Updated README.md
This commit is contained in:
parent
3e91a30e88
commit
e42622bcf6
24
README.md
24
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<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) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user