From 49c12ec87eab62f92bc575be2e7475555b1ef7e3 Mon Sep 17 00:00:00 2001 From: Thor Date: Fri, 20 Oct 2017 12:34:49 +0200 Subject: [PATCH] Added NodePort.GetInputSum --- Scripts/NodePort.cs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Scripts/NodePort.cs b/Scripts/NodePort.cs index 41eb8fa..63f8110 100644 --- a/Scripts/NodePort.cs +++ b/Scripts/NodePort.cs @@ -55,7 +55,6 @@ public class NodePort { } } - /// Return the output value of this node through its parent nodes GetValue override method. /// public object GetOutputValue() { @@ -105,6 +104,30 @@ public class NodePort { return value != null; } + /// Return the sum of all inputs. + /// + public float GetInputSum(float fallback) { + object[] objs = GetInputValues(); + if (objs.Length == 0) return fallback; + float result = 0; + for (int i = 0; i < objs.Length; i++) { + if (objs[i] is float) result += (float)objs[i]; + } + return result; + } + + /// Return the sum of all inputs. + /// + public int GetInputSum(int fallback) { + object[] objs = GetInputValues(); + if (objs.Length == 0) return fallback; + int result = 0; + for (int i = 0; i < objs.Length; i++) { + if (objs[i] is int) result += (int)objs[i]; + } + return result; + } + /// Connect this to another /// The to connect to public void Connect(NodePort port) {