From 4fcaede3b0dcd350364c78943f5ec2e557d9316c Mon Sep 17 00:00:00 2001 From: Thor Date: Fri, 20 Oct 2017 11:41:16 +0200 Subject: [PATCH] NodePort.GetValue changes Removed NodePort.GetValue Added NodePort.GetOutputValue Added NodePort.GetInputValue Added NodePort.GetInputValue Added NodePort.GetInputValues Added NodePort.GetInputValues Added NodePort.TryGetInputValue --- Example/Nodes/ExampleNodeBase.cs | 2 +- Scripts/NodePort.cs | 48 +++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/Example/Nodes/ExampleNodeBase.cs b/Example/Nodes/ExampleNodeBase.cs index c7ad9ff..705c6bc 100644 --- a/Example/Nodes/ExampleNodeBase.cs +++ b/Example/Nodes/ExampleNodeBase.cs @@ -12,7 +12,7 @@ public abstract class ExampleNodeBase : Node { for (int i = 0; i < connectionCount; i++) { NodePort connection = port.GetConnection(i); if (connection == null) continue; - object obj = connection.GetValue(); + object obj = connection.GetOutputValue(); if (obj == null) continue; if (connection.type == typeof(int)) result += (int)obj; else if (connection.type == typeof(float)) result += (float)obj; diff --git a/Scripts/NodePort.cs b/Scripts/NodePort.cs index cdcc9c5..41eb8fa 100644 --- a/Scripts/NodePort.cs +++ b/Scripts/NodePort.cs @@ -55,10 +55,56 @@ public class NodePort { } } - public object GetValue() { + + /// Return the output value of this node through its parent nodes GetValue override method. + /// + public object GetOutputValue() { return node.GetValue(this); } + /// Return the output value of the first connected port. Returns null if none found or invalid. + /// + public object GetInputValue() { + NodePort connectedPort = Connection; + if (connectedPort == null) return null; + return connectedPort.GetOutputValue(); + } + + /// Return the output values of all connected ports. + /// + public object[] GetInputValues() { + object[] objs = new object[ConnectionCount]; + for (int i = 0; i < ConnectionCount; i++) { + NodePort connectedPort = connections[i].Port; + objs[i] = connectedPort.GetOutputValue(); + } + return objs; + } + + /// Return the output value of the first connected port. Returns null if none found or invalid. + /// + public T GetInputValue() where T : class { + return GetInputValue() as T; + } + + /// Return the output values of all connected ports. + /// + public T[] GetInputValues() where T : class { + object[] objs = GetInputValues(); + T[] ts = new T[objs.Length]; + for (int i = 0; i < objs.Length; i++) { + ts[i] = objs[i] as T; + } + return ts; + } + + /// Return true if port is connected and has a valid input. + /// + public bool TryGetInputValue(out T value) where T : class { + value = GetInputValue() as T; + return value != null; + } + /// Connect this to another /// The to connect to public void Connect(NodePort port) {