1
0
mirror of https://github.com/Siccity/xNode.git synced 2025-12-20 01:06:01 +08:00
xNode/Example/Nodes/MathNode.cs
Thor Brigsted 5e68b6bcdc Big update.
Removal of scripts now also clears dependant nodes, to avoid null objects.
NodePorts now support fallback values.
UI Changes.
node.graph is now serialized as well.
2017-10-14 16:19:24 +02:00

32 lines
905 B
C#

using UnityEngine;
[System.Serializable]
public class MathNode : ExampleNodeBase {
[Input(true)] public float a;
[Input(true)] public float b;
[Output(false)] public float result;
public enum MathType { Add, Subtract, Multiply, Divide}
public MathType mathType = MathType.Add;
protected override void Init() {
name = "Math";
}
public override object GetValue(NodePort port) {
float a = GetInputFloat("a");
float b = GetInputFloat("b");
switch(port.fieldName) {
case "result":
switch(mathType) {
case MathType.Add: return a + b;
case MathType.Subtract: return a - b;
case MathType.Multiply: return a * b;
case MathType.Divide: return a / b;
}
break;
}
return 0f;
}
}