mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-20 09:16:01 +08:00
Added T GetInputByFieldName<T>(string fieldName, T fallback = default<T>();
Now retrieving input values is much easier.
As simple as
Material material = GetInputByFieldName("material", this.material);
This commit is contained in:
parent
4c6c10f15b
commit
4de58ad0db
@ -48,6 +48,7 @@ public abstract class Node : ScriptableObject {
|
|||||||
else return GetInputByFieldName(fieldName);
|
else return GetInputByFieldName(fieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary> Returns output port which matches fieldName. Returns null if none found. </summary>
|
/// <summary> Returns output port which matches fieldName. Returns null if none found. </summary>
|
||||||
public NodePort GetOutputByFieldName(string fieldName) {
|
public NodePort GetOutputByFieldName(string fieldName) {
|
||||||
for (int i = 0; i < OutputCount; i++) {
|
for (int i = 0; i < OutputCount; i++) {
|
||||||
@ -56,7 +57,7 @@ public abstract class Node : ScriptableObject {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Returns input port which matches. Returns null if none found. </summary>
|
/// <summary> Returns input port which matches fieldName. Returns null if none found. </summary>
|
||||||
public NodePort GetInputByFieldName(string fieldName) {
|
public NodePort GetInputByFieldName(string fieldName) {
|
||||||
for (int i = 0; i < InputCount; i++) {
|
for (int i = 0; i < InputCount; i++) {
|
||||||
if (inputs[i].fieldName == fieldName) return inputs[i];
|
if (inputs[i].fieldName == fieldName) return inputs[i];
|
||||||
@ -64,6 +65,24 @@ public abstract class Node : ScriptableObject {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary> Return input value 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="fallback">If no ports are connected, this value will be returned</param>
|
||||||
|
public T GetInputByFieldName<T>(string fieldName, T fallback = default(T)) {
|
||||||
|
NodePort port = GetInputByFieldName(fieldName);
|
||||||
|
if (port != null && port.IsConnected) return port.GetInputValue<T>();
|
||||||
|
else return fallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <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="fallback">If no ports are connected, this value will be returned</param>
|
||||||
|
public T[] GetInputsByFieldName<T>(string fieldName, T[] fallback = default(T[])) {
|
||||||
|
NodePort port = GetInputByFieldName(fieldName);
|
||||||
|
if (port != null && port.IsConnected) return port.GetInputValues<T>();
|
||||||
|
else return fallback;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary> Returns a value based on requested port output. Should be overridden before used. </summary>
|
/// <summary> Returns a value based on requested port output. Should be overridden before used. </summary>
|
||||||
/// <param name="port">The requested port.</param>
|
/// <param name="port">The requested port.</param>
|
||||||
public virtual object GetValue(NodePort port) {
|
public virtual object GetValue(NodePort port) {
|
||||||
|
|||||||
@ -82,17 +82,17 @@ 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>() where T : class {
|
public T GetInputValue<T>() {
|
||||||
return GetInputValue() as T;
|
return (T)GetInputValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Return the output values of all connected ports. </summary>
|
/// <summary> Return the output values of all connected ports. </summary>
|
||||||
/// <returns> <see cref="NodePort.GetOutputValue"/> </returns>
|
/// <returns> <see cref="NodePort.GetOutputValue"/> </returns>
|
||||||
public T[] GetInputValues<T>() where T : class {
|
public T[] GetInputValues<T>() {
|
||||||
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] = objs[i] as T;
|
ts[i] = (T)objs[i];
|
||||||
}
|
}
|
||||||
return ts;
|
return ts;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user