mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-20 17:26:02 +08:00
Improved GetInputsByFieldName<T> usage. Added getvalue type checks
This commit is contained in:
parent
e42622bcf6
commit
0150a7bb81
@ -77,7 +77,7 @@ public abstract class Node : ScriptableObject {
|
|||||||
/// <summary> Return all input values for a specified port. Returns fallback value if no ports are connected </summary>
|
/// <summary> Return all input values for a specified port. Returns fallback value if no ports are connected </summary>
|
||||||
/// <param name="fieldName">Field name of requested input port</param>
|
/// <param name="fieldName">Field name of requested input port</param>
|
||||||
/// <param name="fallback">If no ports are connected, this value will be returned</param>
|
/// <param name="fallback">If no ports are connected, this value will be returned</param>
|
||||||
public T[] GetInputsByFieldName<T>(string fieldName, T[] fallback = default(T[])) {
|
public T[] GetInputsByFieldName<T>(string fieldName, params T[] fallback) {
|
||||||
NodePort port = GetInputByFieldName(fieldName);
|
NodePort port = GetInputByFieldName(fieldName);
|
||||||
if (port != null && port.IsConnected) return port.GetInputValues<T>();
|
if (port != null && port.IsConnected) return port.GetInputValues<T>();
|
||||||
else return fallback;
|
else return fallback;
|
||||||
|
|||||||
@ -83,7 +83,8 @@ public class NodePort {
|
|||||||
/// <summary> Return the output value of the first connected port. Returns null if none found or invalid. </summary>
|
/// <summary> Return the output value of the first connected port. Returns null if none found or invalid. </summary>
|
||||||
/// <returns> <see cref="NodePort.GetOutputValue"/> </returns>
|
/// <returns> <see cref="NodePort.GetOutputValue"/> </returns>
|
||||||
public T GetInputValue<T>() {
|
public T GetInputValue<T>() {
|
||||||
return (T)GetInputValue();
|
object obj = GetInputValue();
|
||||||
|
return obj is T ? (T) obj : default(T);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Return the output values of all connected ports. </summary>
|
/// <summary> Return the output values of all connected ports. </summary>
|
||||||
@ -92,16 +93,22 @@ public class NodePort {
|
|||||||
object[] objs = GetInputValues();
|
object[] objs = GetInputValues();
|
||||||
T[] ts = new T[objs.Length];
|
T[] ts = new T[objs.Length];
|
||||||
for (int i = 0; i < objs.Length; i++) {
|
for (int i = 0; i < objs.Length; i++) {
|
||||||
ts[i] = (T)objs[i];
|
if (objs[i] is T) ts[i] = (T) objs[i];
|
||||||
}
|
}
|
||||||
return ts;
|
return ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Return true if port is connected and has a valid input. </summary>
|
/// <summary> Return true if port is connected and has a valid input. </summary>
|
||||||
/// <returns> <see cref="NodePort.GetOutputValue"/> </returns>
|
/// <returns> <see cref="NodePort.GetOutputValue"/> </returns>
|
||||||
public bool TryGetInputValue<T>(out T value) where T : class {
|
public bool TryGetInputValue<T>(out T value) {
|
||||||
value = GetInputValue() as T;
|
object obj = GetInputValue();
|
||||||
return value != null;
|
if (obj is T) {
|
||||||
|
value = (T) obj;
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
value = default(T);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Return the sum of all inputs. </summary>
|
/// <summary> Return the sum of all inputs. </summary>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user