mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-20 09:16:01 +08:00
NodePort.GetValue changes
Removed NodePort.GetValue Added NodePort.GetOutputValue Added NodePort.GetInputValue Added NodePort.GetInputValue<T> Added NodePort.GetInputValues Added NodePort.GetInputValues<T> Added NodePort.TryGetInputValue<T>
This commit is contained in:
parent
9dd784d21e
commit
4fcaede3b0
@ -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;
|
||||
|
||||
@ -55,10 +55,56 @@ public class NodePort {
|
||||
}
|
||||
}
|
||||
|
||||
public object GetValue() {
|
||||
|
||||
/// <summary> Return the output value of this node through its parent nodes GetValue override method. </summary>
|
||||
/// <returns> <see cref="Node.GetValue(NodePort)"/> </returns>
|
||||
public object GetOutputValue() {
|
||||
return node.GetValue(this);
|
||||
}
|
||||
|
||||
/// <summary> Return the output value of the first connected port. Returns null if none found or invalid.</summary>
|
||||
/// <returns> <see cref="NodePort.GetOutputValue"/> </returns>
|
||||
public object GetInputValue() {
|
||||
NodePort connectedPort = Connection;
|
||||
if (connectedPort == null) return null;
|
||||
return connectedPort.GetOutputValue();
|
||||
}
|
||||
|
||||
/// <summary> Return the output values of all connected ports. </summary>
|
||||
/// <returns> <see cref="NodePort.GetOutputValue"/> </returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary> Return the output value of the first connected port. Returns null if none found or invalid. </summary>
|
||||
/// <returns> <see cref="NodePort.GetOutputValue"/> </returns>
|
||||
public T GetInputValue<T>() where T : class {
|
||||
return GetInputValue() as T;
|
||||
}
|
||||
|
||||
/// <summary> Return the output values of all connected ports. </summary>
|
||||
/// <returns> <see cref="NodePort.GetOutputValue"/> </returns>
|
||||
public T[] GetInputValues<T>() 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;
|
||||
}
|
||||
|
||||
/// <summary> Return true if port is connected and has a valid input. </summary>
|
||||
/// <returns> <see cref="NodePort.GetOutputValue"/> </returns>
|
||||
public bool TryGetInputValue<T>(out T value) where T : class {
|
||||
value = GetInputValue() as T;
|
||||
return value != null;
|
||||
}
|
||||
|
||||
/// <summary> Connect this <see cref="NodePort"/> to another </summary>
|
||||
/// <param name="port">The <see cref="NodePort"/> to connect to</param>
|
||||
public void Connect(NodePort port) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user