1
0
mirror of https://github.com/Siccity/xNode.git synced 2025-12-20 09:16:01 +08:00

UPGRADE NOTICE: Renamed 'instance ports' to 'dynamic ports'.

To upgrade, simply rename all your method calls involving instance ports eg. 'AddInstanceOutput' to the dynamic port equivalent eg. 'AddDynamicOutput'
There is no functional difference. The community just agreed this was a more fitting name for the feature.
This commit is contained in:
Thor Brigsted 2019-05-05 10:45:28 +02:00
parent 65162d553e
commit c3e85a9f82
3 changed files with 87 additions and 87 deletions

View File

@ -37,10 +37,10 @@ namespace XNodeEditor {
NodeEditorGUILayout.PropertyField(iterator, true); NodeEditorGUILayout.PropertyField(iterator, true);
} }
// Iterate through instance ports and draw them in the order in which they are serialized // Iterate through dynamic ports and draw them in the order in which they are serialized
foreach (XNode.NodePort instancePort in target.InstancePorts) { foreach (XNode.NodePort dynamicPort in target.DynamicPorts) {
if (NodeEditorGUILayout.IsInstancePortListPort(instancePort)) continue; if (NodeEditorGUILayout.IsDynamicPortListPort(dynamicPort)) continue;
NodeEditorGUILayout.PortField(instancePort); NodeEditorGUILayout.PortField(dynamicPort);
} }
serializedObject.ApplyModifiedProperties(); serializedObject.ApplyModifiedProperties();

View File

@ -50,14 +50,14 @@ namespace XNodeEditor {
// Get data from [Input] attribute // Get data from [Input] attribute
XNode.Node.ShowBackingValue showBacking = XNode.Node.ShowBackingValue.Unconnected; XNode.Node.ShowBackingValue showBacking = XNode.Node.ShowBackingValue.Unconnected;
XNode.Node.InputAttribute inputAttribute; XNode.Node.InputAttribute inputAttribute;
bool instancePortList = false; bool dynamicPortList = false;
if (NodeEditorUtilities.GetCachedAttrib(port.node.GetType(), property.name, out inputAttribute)) { if (NodeEditorUtilities.GetCachedAttrib(port.node.GetType(), property.name, out inputAttribute)) {
instancePortList = inputAttribute.instancePortList; dynamicPortList = inputAttribute.dynamicPortList;
showBacking = inputAttribute.backingValue; showBacking = inputAttribute.backingValue;
} }
//Call GUILayout.Space if Space attribute is set and we are NOT drawing a PropertyField //Call GUILayout.Space if Space attribute is set and we are NOT drawing a PropertyField
bool useLayoutSpace = instancePortList || bool useLayoutSpace = dynamicPortList ||
showBacking == XNode.Node.ShowBackingValue.Never || showBacking == XNode.Node.ShowBackingValue.Never ||
(showBacking == XNode.Node.ShowBackingValue.Unconnected && port.IsConnected); (showBacking == XNode.Node.ShowBackingValue.Unconnected && port.IsConnected);
if (spacePadding > 0 && useLayoutSpace) { if (spacePadding > 0 && useLayoutSpace) {
@ -65,10 +65,10 @@ namespace XNodeEditor {
spacePadding = 0; spacePadding = 0;
} }
if (instancePortList) { if (dynamicPortList) {
Type type = GetType(property); Type type = GetType(property);
XNode.Node.ConnectionType connectionType = inputAttribute != null ? inputAttribute.connectionType : XNode.Node.ConnectionType.Multiple; XNode.Node.ConnectionType connectionType = inputAttribute != null ? inputAttribute.connectionType : XNode.Node.ConnectionType.Multiple;
InstancePortList(property.name, type, property.serializedObject, port.direction, connectionType); DynamicPortList(property.name, type, property.serializedObject, port.direction, connectionType);
return; return;
} }
switch (showBacking) { switch (showBacking) {
@ -95,14 +95,14 @@ namespace XNodeEditor {
// Get data from [Output] attribute // Get data from [Output] attribute
XNode.Node.ShowBackingValue showBacking = XNode.Node.ShowBackingValue.Unconnected; XNode.Node.ShowBackingValue showBacking = XNode.Node.ShowBackingValue.Unconnected;
XNode.Node.OutputAttribute outputAttribute; XNode.Node.OutputAttribute outputAttribute;
bool instancePortList = false; bool dynamicPortList = false;
if (NodeEditorUtilities.GetCachedAttrib(port.node.GetType(), property.name, out outputAttribute)) { if (NodeEditorUtilities.GetCachedAttrib(port.node.GetType(), property.name, out outputAttribute)) {
instancePortList = outputAttribute.instancePortList; dynamicPortList = outputAttribute.dynamicPortList;
showBacking = outputAttribute.backingValue; showBacking = outputAttribute.backingValue;
} }
//Call GUILayout.Space if Space attribute is set and we are NOT drawing a PropertyField //Call GUILayout.Space if Space attribute is set and we are NOT drawing a PropertyField
bool useLayoutSpace = instancePortList || bool useLayoutSpace = dynamicPortList ||
showBacking == XNode.Node.ShowBackingValue.Never || showBacking == XNode.Node.ShowBackingValue.Never ||
(showBacking == XNode.Node.ShowBackingValue.Unconnected && port.IsConnected); (showBacking == XNode.Node.ShowBackingValue.Unconnected && port.IsConnected);
if (spacePadding > 0 && useLayoutSpace) { if (spacePadding > 0 && useLayoutSpace) {
@ -110,10 +110,10 @@ namespace XNodeEditor {
spacePadding = 0; spacePadding = 0;
} }
if (instancePortList) { if (dynamicPortList) {
Type type = GetType(property); Type type = GetType(property);
XNode.Node.ConnectionType connectionType = outputAttribute != null ? outputAttribute.connectionType : XNode.Node.ConnectionType.Multiple; XNode.Node.ConnectionType connectionType = outputAttribute != null ? outputAttribute.connectionType : XNode.Node.ConnectionType.Multiple;
InstancePortList(property.name, type, property.serializedObject, port.direction, connectionType); DynamicPortList(property.name, type, property.serializedObject, port.direction, connectionType);
return; return;
} }
switch (showBacking) { switch (showBacking) {
@ -254,8 +254,8 @@ namespace XNodeEditor {
GUI.color = col; GUI.color = col;
} }
/// <summary> Is this port part of an InstancePortList? </summary> /// <summary> Is this port part of a DynamicPortList? </summary>
public static bool IsInstancePortListPort(XNode.NodePort port) { public static bool IsDynamicPortListPort(XNode.NodePort port) {
string[] parts = port.fieldName.Split(' '); string[] parts = port.fieldName.Split(' ');
if (parts.Length != 2) return false; if (parts.Length != 2) return false;
Dictionary<string, ReorderableList> cache; Dictionary<string, ReorderableList> cache;
@ -266,16 +266,16 @@ namespace XNodeEditor {
return false; return false;
} }
/// <summary> Draw an editable list of instance ports. Port names are named as "[fieldName] [index]" </summary> /// <summary> Draw an editable list of dynamic ports. Port names are named as "[fieldName] [index]" </summary>
/// <param name="fieldName">Supply a list for editable values</param> /// <param name="fieldName">Supply a list for editable values</param>
/// <param name="type">Value type of added instance ports</param> /// <param name="type">Value type of added dynamic ports</param>
/// <param name="serializedObject">The serializedObject of the node</param> /// <param name="serializedObject">The serializedObject of the node</param>
/// <param name="connectionType">Connection type of added instance ports</param> /// <param name="connectionType">Connection type of added dynamic ports</param>
/// <param name="onCreation">Called on the list on creation. Use this if you want to customize the created ReorderableList</param> /// <param name="onCreation">Called on the list on creation. Use this if you want to customize the created ReorderableList</param>
public static void InstancePortList(string fieldName, Type type, SerializedObject serializedObject, XNode.NodePort.IO io, XNode.Node.ConnectionType connectionType = XNode.Node.ConnectionType.Multiple, XNode.Node.TypeConstraint typeConstraint = XNode.Node.TypeConstraint.None, Action<ReorderableList> onCreation = null) { public static void DynamicPortList(string fieldName, Type type, SerializedObject serializedObject, XNode.NodePort.IO io, XNode.Node.ConnectionType connectionType = XNode.Node.ConnectionType.Multiple, XNode.Node.TypeConstraint typeConstraint = XNode.Node.TypeConstraint.None, Action<ReorderableList> onCreation = null) {
XNode.Node node = serializedObject.targetObject as XNode.Node; XNode.Node node = serializedObject.targetObject as XNode.Node;
var indexedPorts = node.InstancePorts.Select(x => { var indexedPorts = node.DynamicPorts.Select(x => {
string[] split = x.fieldName.Split(' '); string[] split = x.fieldName.Split(' ');
if (split != null && split.Length == 2 && split[0] == fieldName) { if (split != null && split.Length == 2 && split[0] == fieldName) {
int i = -1; int i = -1;
@ -285,7 +285,7 @@ namespace XNodeEditor {
} }
return new { index = -1, port = (XNode.NodePort) null }; return new { index = -1, port = (XNode.NodePort) null };
}); });
List<XNode.NodePort> instancePorts = indexedPorts.OrderBy(x => x.index).Select(x => x.port).ToList(); List<XNode.NodePort> dynamicPorts = indexedPorts.OrderBy(x => x.index).Select(x => x.port).ToList();
ReorderableList list = null; ReorderableList list = null;
Dictionary<string, ReorderableList> rlc; Dictionary<string, ReorderableList> rlc;
@ -295,18 +295,18 @@ namespace XNodeEditor {
// If a ReorderableList isn't cached for this array, do so. // If a ReorderableList isn't cached for this array, do so.
if (list == null) { if (list == null) {
SerializedProperty arrayData = serializedObject.FindProperty(fieldName); SerializedProperty arrayData = serializedObject.FindProperty(fieldName);
list = CreateReorderableList(fieldName, instancePorts, arrayData, type, serializedObject, io, connectionType, typeConstraint, onCreation); list = CreateReorderableList(fieldName, dynamicPorts, arrayData, type, serializedObject, io, connectionType, typeConstraint, onCreation);
if (reorderableListCache.TryGetValue(serializedObject.targetObject, out rlc)) rlc.Add(fieldName, list); if (reorderableListCache.TryGetValue(serializedObject.targetObject, out rlc)) rlc.Add(fieldName, list);
else reorderableListCache.Add(serializedObject.targetObject, new Dictionary<string, ReorderableList>() { { fieldName, list } }); else reorderableListCache.Add(serializedObject.targetObject, new Dictionary<string, ReorderableList>() { { fieldName, list } });
} }
list.list = instancePorts; list.list = dynamicPorts;
list.DoLayoutList(); list.DoLayoutList();
} }
private static ReorderableList CreateReorderableList(string fieldName, List<XNode.NodePort> instancePorts, SerializedProperty arrayData, Type type, SerializedObject serializedObject, XNode.NodePort.IO io, XNode.Node.ConnectionType connectionType, XNode.Node.TypeConstraint typeConstraint, Action<ReorderableList> onCreation) { private static ReorderableList CreateReorderableList(string fieldName, List<XNode.NodePort> dynamicPorts, SerializedProperty arrayData, Type type, SerializedObject serializedObject, XNode.NodePort.IO io, XNode.Node.ConnectionType connectionType, XNode.Node.TypeConstraint typeConstraint, Action<ReorderableList> onCreation) {
bool hasArrayData = arrayData != null && arrayData.isArray; bool hasArrayData = arrayData != null && arrayData.isArray;
XNode.Node node = serializedObject.targetObject as XNode.Node; XNode.Node node = serializedObject.targetObject as XNode.Node;
ReorderableList list = new ReorderableList(instancePorts, null, true, true, true, true); ReorderableList list = new ReorderableList(dynamicPorts, null, true, true, true, true);
string label = arrayData != null ? arrayData.displayName : ObjectNames.NicifyVariableName(fieldName); string label = arrayData != null ? arrayData.displayName : ObjectNames.NicifyVariableName(fieldName);
list.drawElementCallback = list.drawElementCallback =
@ -387,13 +387,13 @@ namespace XNodeEditor {
}; };
list.onAddCallback = list.onAddCallback =
(ReorderableList rl) => { (ReorderableList rl) => {
// Add instance port postfixed with an index number // Add dynamic port postfixed with an index number
string newName = fieldName + " 0"; string newName = fieldName + " 0";
int i = 0; int i = 0;
while (node.HasPort(newName)) newName = fieldName + " " + (++i); while (node.HasPort(newName)) newName = fieldName + " " + (++i);
if (io == XNode.NodePort.IO.Output) node.AddInstanceOutput(type, connectionType, XNode.Node.TypeConstraint.None, newName); if (io == XNode.NodePort.IO.Output) node.AddDynamicOutput(type, connectionType, XNode.Node.TypeConstraint.None, newName);
else node.AddInstanceInput(type, connectionType, typeConstraint, newName); else node.AddDynamicInput(type, connectionType, typeConstraint, newName);
serializedObject.Update(); serializedObject.Update();
EditorUtility.SetDirty(node); EditorUtility.SetDirty(node);
if (hasArrayData) { if (hasArrayData) {
@ -404,7 +404,7 @@ namespace XNodeEditor {
list.onRemoveCallback = list.onRemoveCallback =
(ReorderableList rl) => { (ReorderableList rl) => {
var indexedPorts = node.InstancePorts.Select(x => { var indexedPorts = node.DynamicPorts.Select(x => {
string[] split = x.fieldName.Split(' '); string[] split = x.fieldName.Split(' ');
if (split != null && split.Length == 2 && split[0] == fieldName) { if (split != null && split.Length == 2 && split[0] == fieldName) {
int i = -1; int i = -1;
@ -414,37 +414,37 @@ namespace XNodeEditor {
} }
return new { index = -1, port = (XNode.NodePort) null }; return new { index = -1, port = (XNode.NodePort) null };
}); });
instancePorts = indexedPorts.OrderBy(x => x.index).Select(x => x.port).ToList(); dynamicPorts = indexedPorts.OrderBy(x => x.index).Select(x => x.port).ToList();
int index = rl.index; int index = rl.index;
if (instancePorts.Count > index) { if (dynamicPorts.Count > index) {
// Clear the removed ports connections // Clear the removed ports connections
instancePorts[index].ClearConnections(); dynamicPorts[index].ClearConnections();
// Move following connections one step up to replace the missing connection // Move following connections one step up to replace the missing connection
for (int k = index + 1; k < instancePorts.Count(); k++) { for (int k = index + 1; k < dynamicPorts.Count(); k++) {
for (int j = 0; j < instancePorts[k].ConnectionCount; j++) { for (int j = 0; j < dynamicPorts[k].ConnectionCount; j++) {
XNode.NodePort other = instancePorts[k].GetConnection(j); XNode.NodePort other = dynamicPorts[k].GetConnection(j);
instancePorts[k].Disconnect(other); dynamicPorts[k].Disconnect(other);
instancePorts[k - 1].Connect(other); dynamicPorts[k - 1].Connect(other);
} }
} }
// Remove the last instance port, to avoid messing up the indexing // Remove the last dynamic port, to avoid messing up the indexing
node.RemoveInstancePort(instancePorts[instancePorts.Count() - 1].fieldName); node.RemoveDynamicPort(dynamicPorts[dynamicPorts.Count() - 1].fieldName);
serializedObject.Update(); serializedObject.Update();
EditorUtility.SetDirty(node); EditorUtility.SetDirty(node);
} else { } else {
Debug.LogWarning("InstancePorts[" + index + "] out of range. Length was " + instancePorts.Count + ". Skipping."); Debug.LogWarning("DynamicPorts[" + index + "] out of range. Length was " + dynamicPorts.Count + ". Skipping.");
} }
if (hasArrayData) { if (hasArrayData) {
arrayData.DeleteArrayElementAtIndex(index); arrayData.DeleteArrayElementAtIndex(index);
// Error handling. If the following happens too often, file a bug report at https://github.com/Siccity/xNode/issues // Error handling. If the following happens too often, file a bug report at https://github.com/Siccity/xNode/issues
if (instancePorts.Count <= arrayData.arraySize) { if (dynamicPorts.Count <= arrayData.arraySize) {
while (instancePorts.Count <= arrayData.arraySize) { while (dynamicPorts.Count <= arrayData.arraySize) {
arrayData.DeleteArrayElementAtIndex(arrayData.arraySize - 1); arrayData.DeleteArrayElementAtIndex(arrayData.arraySize - 1);
} }
UnityEngine.Debug.LogWarning("Array size exceeded instance ports size. Excess items removed."); UnityEngine.Debug.LogWarning("Array size exceeded dynamic ports size. Excess items removed.");
} }
serializedObject.ApplyModifiedProperties(); serializedObject.ApplyModifiedProperties();
serializedObject.Update(); serializedObject.Update();
@ -452,18 +452,18 @@ namespace XNodeEditor {
}; };
if (hasArrayData) { if (hasArrayData) {
int instancePortCount = instancePorts.Count; int dynamicPortCount = dynamicPorts.Count;
while (instancePortCount < arrayData.arraySize) { while (dynamicPortCount < arrayData.arraySize) {
// Add instance port postfixed with an index number // Add dynamic port postfixed with an index number
string newName = arrayData.name + " 0"; string newName = arrayData.name + " 0";
int i = 0; int i = 0;
while (node.HasPort(newName)) newName = arrayData.name + " " + (++i); while (node.HasPort(newName)) newName = arrayData.name + " " + (++i);
if (io == XNode.NodePort.IO.Output) node.AddInstanceOutput(type, connectionType, typeConstraint, newName); if (io == XNode.NodePort.IO.Output) node.AddDynamicOutput(type, connectionType, typeConstraint, newName);
else node.AddInstanceInput(type, connectionType, typeConstraint, newName); else node.AddDynamicInput(type, connectionType, typeConstraint, newName);
EditorUtility.SetDirty(node); EditorUtility.SetDirty(node);
instancePortCount++; dynamicPortCount++;
} }
while (arrayData.arraySize < instancePortCount) { while (arrayData.arraySize < dynamicPortCount) {
arrayData.InsertArrayElementAtIndex(arrayData.arraySize); arrayData.InsertArrayElementAtIndex(arrayData.arraySize);
} }
serializedObject.ApplyModifiedProperties(); serializedObject.ApplyModifiedProperties();

View File

@ -57,12 +57,12 @@ namespace XNode {
public IEnumerable<NodePort> Outputs { get { foreach (NodePort port in Ports) { if (port.IsOutput) yield return port; } } } public IEnumerable<NodePort> Outputs { get { foreach (NodePort port in Ports) { if (port.IsOutput) yield return port; } } }
/// <summary> Iterate over all inputs on this node. </summary> /// <summary> Iterate over all inputs on this node. </summary>
public IEnumerable<NodePort> Inputs { get { foreach (NodePort port in Ports) { if (port.IsInput) yield return port; } } } public IEnumerable<NodePort> Inputs { get { foreach (NodePort port in Ports) { if (port.IsInput) yield return port; } } }
/// <summary> Iterate over all instane ports on this node. </summary> /// <summary> Iterate over all dynamic ports on this node. </summary>
public IEnumerable<NodePort> InstancePorts { get { foreach (NodePort port in Ports) { if (port.IsDynamic) yield return port; } } } public IEnumerable<NodePort> DynamicPorts { get { foreach (NodePort port in Ports) { if (port.IsDynamic) yield return port; } } }
/// <summary> Iterate over all instance outputs on this node. </summary> /// <summary> Iterate over all dynamic outputs on this node. </summary>
public IEnumerable<NodePort> InstanceOutputs { get { foreach (NodePort port in Ports) { if (port.IsDynamic && port.IsOutput) yield return port; } } } public IEnumerable<NodePort> DynamicOutputs { get { foreach (NodePort port in Ports) { if (port.IsDynamic && port.IsOutput) yield return port; } } }
/// <summary> Iterate over all instance inputs on this node. </summary> /// <summary> Iterate over all dynamic inputs on this node. </summary>
public IEnumerable<NodePort> InstanceInputs { get { foreach (NodePort port in Ports) { if (port.IsDynamic && port.IsInput) yield return port; } } } public IEnumerable<NodePort> DynamicInputs { get { foreach (NodePort port in Ports) { if (port.IsDynamic && port.IsInput) yield return port; } } }
/// <summary> Parent <see cref="NodeGraph"/> </summary> /// <summary> Parent <see cref="NodeGraph"/> </summary>
[SerializeField] public NodeGraph graph; [SerializeField] public NodeGraph graph;
/// <summary> Position on the <see cref="NodeGraph"/> </summary> /// <summary> Position on the <see cref="NodeGraph"/> </summary>
@ -97,25 +97,25 @@ namespace XNode {
/// <summary> Convenience function. </summary> /// <summary> Convenience function. </summary>
/// <seealso cref="AddInstancePort"/> /// <seealso cref="AddInstancePort"/>
/// <seealso cref="AddInstanceOutput"/> /// <seealso cref="AddInstanceOutput"/>
public NodePort AddInstanceInput(Type type, Node.ConnectionType connectionType = Node.ConnectionType.Multiple, Node.TypeConstraint typeConstraint = TypeConstraint.None, string fieldName = null) { public NodePort AddDynamicInput(Type type, Node.ConnectionType connectionType = Node.ConnectionType.Multiple, Node.TypeConstraint typeConstraint = TypeConstraint.None, string fieldName = null) {
return AddInstancePort(type, NodePort.IO.Input, connectionType, typeConstraint, fieldName); return AddDynamicPort(type, NodePort.IO.Input, connectionType, typeConstraint, fieldName);
} }
/// <summary> Convenience function. </summary> /// <summary> Convenience function. </summary>
/// <seealso cref="AddInstancePort"/> /// <seealso cref="AddInstancePort"/>
/// <seealso cref="AddInstanceInput"/> /// <seealso cref="AddInstanceInput"/>
public NodePort AddInstanceOutput(Type type, Node.ConnectionType connectionType = Node.ConnectionType.Multiple, Node.TypeConstraint typeConstraint = TypeConstraint.None, string fieldName = null) { public NodePort AddDynamicOutput(Type type, Node.ConnectionType connectionType = Node.ConnectionType.Multiple, Node.TypeConstraint typeConstraint = TypeConstraint.None, string fieldName = null) {
return AddInstancePort(type, NodePort.IO.Output, connectionType, typeConstraint, fieldName); return AddDynamicPort(type, NodePort.IO.Output, connectionType, typeConstraint, fieldName);
} }
/// <summary> Add a dynamic, serialized port to this node. </summary> /// <summary> Add a dynamic, serialized port to this node. </summary>
/// <seealso cref="AddInstanceInput"/> /// <seealso cref="AddDynamicInput"/>
/// <seealso cref="AddInstanceOutput"/> /// <seealso cref="AddDynamicOutput"/>
private NodePort AddInstancePort(Type type, NodePort.IO direction, Node.ConnectionType connectionType = Node.ConnectionType.Multiple, Node.TypeConstraint typeConstraint = TypeConstraint.None, string fieldName = null) { private NodePort AddDynamicPort(Type type, NodePort.IO direction, Node.ConnectionType connectionType = Node.ConnectionType.Multiple, Node.TypeConstraint typeConstraint = TypeConstraint.None, string fieldName = null) {
if (fieldName == null) { if (fieldName == null) {
fieldName = "instanceInput_0"; fieldName = "dynamicInput_0";
int i = 0; int i = 0;
while (HasPort(fieldName)) fieldName = "instanceInput_" + (++i); while (HasPort(fieldName)) fieldName = "dynamicInput_" + (++i);
} else if (HasPort(fieldName)) { } else if (HasPort(fieldName)) {
Debug.LogWarning("Port '" + fieldName + "' already exists in " + name, this); Debug.LogWarning("Port '" + fieldName + "' already exists in " + name, this);
return ports[fieldName]; return ports[fieldName];
@ -125,27 +125,27 @@ namespace XNode {
return port; return port;
} }
/// <summary> Remove an instance port from the node </summary> /// <summary> Remove an dynamic port from the node </summary>
public void RemoveInstancePort(string fieldName) { public void RemoveDynamicPort(string fieldName) {
NodePort instancePort = GetPort(fieldName); NodePort dynamicPort = GetPort(fieldName);
if (instancePort == null) throw new ArgumentException("port " + fieldName + " doesn't exist"); if (dynamicPort == null) throw new ArgumentException("port " + fieldName + " doesn't exist");
RemoveInstancePort(GetPort(fieldName)); RemoveDynamicPort(GetPort(fieldName));
} }
/// <summary> Remove an instance port from the node </summary> /// <summary> Remove an dynamic port from the node </summary>
public void RemoveInstancePort(NodePort port) { public void RemoveDynamicPort(NodePort port) {
if (port == null) throw new ArgumentNullException("port"); if (port == null) throw new ArgumentNullException("port");
else if (port.IsStatic) throw new ArgumentException("cannot remove static port"); else if (port.IsStatic) throw new ArgumentException("cannot remove static port");
port.ClearConnections(); port.ClearConnections();
ports.Remove(port.fieldName); ports.Remove(port.fieldName);
} }
/// <summary> Removes all instance ports from the node </summary> /// <summary> Removes all dynamic ports from the node </summary>
[ContextMenu("Clear Instance Ports")] [ContextMenu("Clear Dynamic Ports")]
public void ClearInstancePorts() { public void ClearDynamicPorts() {
List<NodePort> instancePorts = new List<NodePort>(InstancePorts); List<NodePort> dynamicPorts = new List<NodePort>(DynamicPorts);
foreach (NodePort port in instancePorts) { foreach (NodePort port in dynamicPorts) {
RemoveInstancePort(port); RemoveDynamicPort(port);
} }
} }
#endregion #endregion
@ -223,18 +223,18 @@ namespace XNode {
public class InputAttribute : Attribute { public class InputAttribute : Attribute {
public ShowBackingValue backingValue; public ShowBackingValue backingValue;
public ConnectionType connectionType; public ConnectionType connectionType;
public bool instancePortList; public bool dynamicPortList;
public TypeConstraint typeConstraint; public TypeConstraint typeConstraint;
/// <summary> Mark a serializable field as an input port. You can access this through <see cref="GetInputPort(string)"/> </summary> /// <summary> Mark a serializable field as an input port. You can access this through <see cref="GetInputPort(string)"/> </summary>
/// <param name="backingValue">Should we display the backing value for this port as an editor field? </param> /// <param name="backingValue">Should we display the backing value for this port as an editor field? </param>
/// <param name="connectionType">Should we allow multiple connections? </param> /// <param name="connectionType">Should we allow multiple connections? </param>
/// <param name="typeConstraint">Constrains which input connections can be made to this port </param> /// <param name="typeConstraint">Constrains which input connections can be made to this port </param>
/// <param name="instancePortList">If true, will display a reorderable list of inputs instead of a single port. Will automatically add and display values for lists and arrays </param> /// <param name="dynamicPortList">If true, will display a reorderable list of inputs instead of a single port. Will automatically add and display values for lists and arrays </param>
public InputAttribute(ShowBackingValue backingValue = ShowBackingValue.Unconnected, ConnectionType connectionType = ConnectionType.Multiple, TypeConstraint typeConstraint = TypeConstraint.None, bool instancePortList = false) { public InputAttribute(ShowBackingValue backingValue = ShowBackingValue.Unconnected, ConnectionType connectionType = ConnectionType.Multiple, TypeConstraint typeConstraint = TypeConstraint.None, bool dynamicPortList = false) {
this.backingValue = backingValue; this.backingValue = backingValue;
this.connectionType = connectionType; this.connectionType = connectionType;
this.instancePortList = instancePortList; this.dynamicPortList = dynamicPortList;
this.typeConstraint = typeConstraint; this.typeConstraint = typeConstraint;
} }
} }
@ -244,16 +244,16 @@ namespace XNode {
public class OutputAttribute : Attribute { public class OutputAttribute : Attribute {
public ShowBackingValue backingValue; public ShowBackingValue backingValue;
public ConnectionType connectionType; public ConnectionType connectionType;
public bool instancePortList; public bool dynamicPortList;
/// <summary> Mark a serializable field as an output port. You can access this through <see cref="GetOutputPort(string)"/> </summary> /// <summary> Mark a serializable field as an output port. You can access this through <see cref="GetOutputPort(string)"/> </summary>
/// <param name="backingValue">Should we display the backing value for this port as an editor field? </param> /// <param name="backingValue">Should we display the backing value for this port as an editor field? </param>
/// <param name="connectionType">Should we allow multiple connections? </param> /// <param name="connectionType">Should we allow multiple connections? </param>
/// <param name="instancePortList">If true, will display a reorderable list of outputs instead of a single port. Will automatically add and display values for lists and arrays </param> /// <param name="dynamicPortList">If true, will display a reorderable list of outputs instead of a single port. Will automatically add and display values for lists and arrays </param>
public OutputAttribute(ShowBackingValue backingValue = ShowBackingValue.Never, ConnectionType connectionType = ConnectionType.Multiple, bool instancePortList = false) { public OutputAttribute(ShowBackingValue backingValue = ShowBackingValue.Never, ConnectionType connectionType = ConnectionType.Multiple, bool dynamicPortList = false) {
this.backingValue = backingValue; this.backingValue = backingValue;
this.connectionType = connectionType; this.connectionType = connectionType;
this.instancePortList = instancePortList; this.dynamicPortList = dynamicPortList;
} }
} }