diff --git a/Scripts/Node.cs b/Scripts/Node.cs
index 503219e..dba0a01 100644
--- a/Scripts/Node.cs
+++ b/Scripts/Node.cs
@@ -48,6 +48,7 @@ public abstract class Node : ScriptableObject {
else return GetInputByFieldName(fieldName);
}
+
/// Returns output port which matches fieldName. Returns null if none found.
public NodePort GetOutputByFieldName(string fieldName) {
for (int i = 0; i < OutputCount; i++) {
@@ -56,7 +57,7 @@ public abstract class Node : ScriptableObject {
return null;
}
- /// Returns input port which matches. Returns null if none found.
+ /// Returns input port which matches fieldName. Returns null if none found.
public NodePort GetInputByFieldName(string fieldName) {
for (int i = 0; i < InputCount; i++) {
if (inputs[i].fieldName == fieldName) return inputs[i];
@@ -64,6 +65,24 @@ public abstract class Node : ScriptableObject {
return null;
}
+ /// Return input value for a specified port. Returns fallback value if no ports are connected
+ /// Field name of requested input port
+ /// If no ports are connected, this value will be returned
+ public T GetInputByFieldName(string fieldName, T fallback = default(T)) {
+ NodePort port = GetInputByFieldName(fieldName);
+ if (port != null && port.IsConnected) return port.GetInputValue();
+ else return fallback;
+ }
+
+ /// Return all input values for a specified port. Returns fallback value if no ports are connected
+ /// Field name of requested input port
+ /// If no ports are connected, this value will be returned
+ public T[] GetInputsByFieldName(string fieldName, T[] fallback = default(T[])) {
+ NodePort port = GetInputByFieldName(fieldName);
+ if (port != null && port.IsConnected) return port.GetInputValues();
+ else return fallback;
+ }
+
/// Returns a value based on requested port output. Should be overridden before used.
/// The requested port.
public virtual object GetValue(NodePort port) {
diff --git a/Scripts/NodePort.cs b/Scripts/NodePort.cs
index 63f8110..93845cc 100644
--- a/Scripts/NodePort.cs
+++ b/Scripts/NodePort.cs
@@ -82,17 +82,17 @@ public class NodePort {
/// 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;
+ public T GetInputValue() {
+ return (T)GetInputValue();
}
/// Return the output values of all connected ports.
///
- public T[] GetInputValues() where T : class {
+ public T[] GetInputValues() {
object[] objs = GetInputValues();
T[] ts = new T[objs.Length];
for (int i = 0; i < objs.Length; i++) {
- ts[i] = objs[i] as T;
+ ts[i] = (T)objs[i];
}
return ts;
}