diff --git a/Scripts/Editor/NodeEditor.cs b/Scripts/Editor/NodeEditor.cs
index a6d1748..91d92d0 100644
--- a/Scripts/Editor/NodeEditor.cs
+++ b/Scripts/Editor/NodeEditor.cs
@@ -37,10 +37,10 @@ namespace XNodeEditor {
NodeEditorGUILayout.PropertyField(iterator, true);
}
- // Iterate through instance ports and draw them in the order in which they are serialized
- foreach (XNode.NodePort instancePort in target.InstancePorts) {
- if (NodeEditorGUILayout.IsInstancePortListPort(instancePort)) continue;
- NodeEditorGUILayout.PortField(instancePort);
+ // Iterate through dynamic ports and draw them in the order in which they are serialized
+ foreach (XNode.NodePort dynamicPort in target.DynamicPorts) {
+ if (NodeEditorGUILayout.IsDynamicPortListPort(dynamicPort)) continue;
+ NodeEditorGUILayout.PortField(dynamicPort);
}
serializedObject.ApplyModifiedProperties();
diff --git a/Scripts/Editor/NodeEditorGUILayout.cs b/Scripts/Editor/NodeEditorGUILayout.cs
index a1c5d83..7c4de29 100644
--- a/Scripts/Editor/NodeEditorGUILayout.cs
+++ b/Scripts/Editor/NodeEditorGUILayout.cs
@@ -50,14 +50,14 @@ namespace XNodeEditor {
// Get data from [Input] attribute
XNode.Node.ShowBackingValue showBacking = XNode.Node.ShowBackingValue.Unconnected;
XNode.Node.InputAttribute inputAttribute;
- bool instancePortList = false;
+ bool dynamicPortList = false;
if (NodeEditorUtilities.GetCachedAttrib(port.node.GetType(), property.name, out inputAttribute)) {
- instancePortList = inputAttribute.instancePortList;
+ dynamicPortList = inputAttribute.dynamicPortList;
showBacking = inputAttribute.backingValue;
}
//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.Unconnected && port.IsConnected);
if (spacePadding > 0 && useLayoutSpace) {
@@ -65,10 +65,10 @@ namespace XNodeEditor {
spacePadding = 0;
}
- if (instancePortList) {
+ if (dynamicPortList) {
Type type = GetType(property);
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;
}
switch (showBacking) {
@@ -95,14 +95,14 @@ namespace XNodeEditor {
// Get data from [Output] attribute
XNode.Node.ShowBackingValue showBacking = XNode.Node.ShowBackingValue.Unconnected;
XNode.Node.OutputAttribute outputAttribute;
- bool instancePortList = false;
+ bool dynamicPortList = false;
if (NodeEditorUtilities.GetCachedAttrib(port.node.GetType(), property.name, out outputAttribute)) {
- instancePortList = outputAttribute.instancePortList;
+ dynamicPortList = outputAttribute.dynamicPortList;
showBacking = outputAttribute.backingValue;
}
//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.Unconnected && port.IsConnected);
if (spacePadding > 0 && useLayoutSpace) {
@@ -110,10 +110,10 @@ namespace XNodeEditor {
spacePadding = 0;
}
- if (instancePortList) {
+ if (dynamicPortList) {
Type type = GetType(property);
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;
}
switch (showBacking) {
@@ -254,8 +254,8 @@ namespace XNodeEditor {
GUI.color = col;
}
- /// Is this port part of an InstancePortList?
- public static bool IsInstancePortListPort(XNode.NodePort port) {
+ /// Is this port part of a DynamicPortList?
+ public static bool IsDynamicPortListPort(XNode.NodePort port) {
string[] parts = port.fieldName.Split(' ');
if (parts.Length != 2) return false;
Dictionary cache;
@@ -266,16 +266,16 @@ namespace XNodeEditor {
return false;
}
- /// Draw an editable list of instance ports. Port names are named as "[fieldName] [index]"
+ /// Draw an editable list of dynamic ports. Port names are named as "[fieldName] [index]"
/// Supply a list for editable values
- /// Value type of added instance ports
+ /// Value type of added dynamic ports
/// The serializedObject of the node
- /// Connection type of added instance ports
+ /// Connection type of added dynamic ports
/// Called on the list on creation. Use this if you want to customize the created ReorderableList
- 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 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 onCreation = null) {
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(' ');
if (split != null && split.Length == 2 && split[0] == fieldName) {
int i = -1;
@@ -285,7 +285,7 @@ namespace XNodeEditor {
}
return new { index = -1, port = (XNode.NodePort) null };
});
- List instancePorts = indexedPorts.OrderBy(x => x.index).Select(x => x.port).ToList();
+ List dynamicPorts = indexedPorts.OrderBy(x => x.index).Select(x => x.port).ToList();
ReorderableList list = null;
Dictionary rlc;
@@ -295,18 +295,18 @@ namespace XNodeEditor {
// If a ReorderableList isn't cached for this array, do so.
if (list == null) {
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);
else reorderableListCache.Add(serializedObject.targetObject, new Dictionary() { { fieldName, list } });
}
- list.list = instancePorts;
+ list.list = dynamicPorts;
list.DoLayoutList();
}
- private static ReorderableList CreateReorderableList(string fieldName, List instancePorts, SerializedProperty arrayData, Type type, SerializedObject serializedObject, XNode.NodePort.IO io, XNode.Node.ConnectionType connectionType, XNode.Node.TypeConstraint typeConstraint, Action onCreation) {
+ private static ReorderableList CreateReorderableList(string fieldName, List dynamicPorts, SerializedProperty arrayData, Type type, SerializedObject serializedObject, XNode.NodePort.IO io, XNode.Node.ConnectionType connectionType, XNode.Node.TypeConstraint typeConstraint, Action onCreation) {
bool hasArrayData = arrayData != null && arrayData.isArray;
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);
list.drawElementCallback =
@@ -387,13 +387,13 @@ namespace XNodeEditor {
};
list.onAddCallback =
(ReorderableList rl) => {
- // Add instance port postfixed with an index number
+ // Add dynamic port postfixed with an index number
string newName = fieldName + " 0";
int i = 0;
while (node.HasPort(newName)) newName = fieldName + " " + (++i);
- if (io == XNode.NodePort.IO.Output) node.AddInstanceOutput(type, connectionType, XNode.Node.TypeConstraint.None, newName);
- else node.AddInstanceInput(type, connectionType, typeConstraint, newName);
+ if (io == XNode.NodePort.IO.Output) node.AddDynamicOutput(type, connectionType, XNode.Node.TypeConstraint.None, newName);
+ else node.AddDynamicInput(type, connectionType, typeConstraint, newName);
serializedObject.Update();
EditorUtility.SetDirty(node);
if (hasArrayData) {
@@ -404,7 +404,7 @@ namespace XNodeEditor {
list.onRemoveCallback =
(ReorderableList rl) => {
- var indexedPorts = node.InstancePorts.Select(x => {
+ var indexedPorts = node.DynamicPorts.Select(x => {
string[] split = x.fieldName.Split(' ');
if (split != null && split.Length == 2 && split[0] == fieldName) {
int i = -1;
@@ -414,37 +414,37 @@ namespace XNodeEditor {
}
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;
- if (instancePorts.Count > index) {
+ if (dynamicPorts.Count > index) {
// Clear the removed ports connections
- instancePorts[index].ClearConnections();
+ dynamicPorts[index].ClearConnections();
// Move following connections one step up to replace the missing connection
- for (int k = index + 1; k < instancePorts.Count(); k++) {
- for (int j = 0; j < instancePorts[k].ConnectionCount; j++) {
- XNode.NodePort other = instancePorts[k].GetConnection(j);
- instancePorts[k].Disconnect(other);
- instancePorts[k - 1].Connect(other);
+ for (int k = index + 1; k < dynamicPorts.Count(); k++) {
+ for (int j = 0; j < dynamicPorts[k].ConnectionCount; j++) {
+ XNode.NodePort other = dynamicPorts[k].GetConnection(j);
+ dynamicPorts[k].Disconnect(other);
+ dynamicPorts[k - 1].Connect(other);
}
}
- // Remove the last instance port, to avoid messing up the indexing
- node.RemoveInstancePort(instancePorts[instancePorts.Count() - 1].fieldName);
+ // Remove the last dynamic port, to avoid messing up the indexing
+ node.RemoveDynamicPort(dynamicPorts[dynamicPorts.Count() - 1].fieldName);
serializedObject.Update();
EditorUtility.SetDirty(node);
} 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) {
arrayData.DeleteArrayElementAtIndex(index);
// Error handling. If the following happens too often, file a bug report at https://github.com/Siccity/xNode/issues
- if (instancePorts.Count <= arrayData.arraySize) {
- while (instancePorts.Count <= arrayData.arraySize) {
+ if (dynamicPorts.Count <= arrayData.arraySize) {
+ while (dynamicPorts.Count <= arrayData.arraySize) {
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.Update();
@@ -452,18 +452,18 @@ namespace XNodeEditor {
};
if (hasArrayData) {
- int instancePortCount = instancePorts.Count;
- while (instancePortCount < arrayData.arraySize) {
- // Add instance port postfixed with an index number
+ int dynamicPortCount = dynamicPorts.Count;
+ while (dynamicPortCount < arrayData.arraySize) {
+ // Add dynamic port postfixed with an index number
string newName = arrayData.name + " 0";
int i = 0;
while (node.HasPort(newName)) newName = arrayData.name + " " + (++i);
- if (io == XNode.NodePort.IO.Output) node.AddInstanceOutput(type, connectionType, typeConstraint, newName);
- else node.AddInstanceInput(type, connectionType, typeConstraint, newName);
+ if (io == XNode.NodePort.IO.Output) node.AddDynamicOutput(type, connectionType, typeConstraint, newName);
+ else node.AddDynamicInput(type, connectionType, typeConstraint, newName);
EditorUtility.SetDirty(node);
- instancePortCount++;
+ dynamicPortCount++;
}
- while (arrayData.arraySize < instancePortCount) {
+ while (arrayData.arraySize < dynamicPortCount) {
arrayData.InsertArrayElementAtIndex(arrayData.arraySize);
}
serializedObject.ApplyModifiedProperties();
diff --git a/Scripts/Node.cs b/Scripts/Node.cs
index 74eb309..895abbb 100644
--- a/Scripts/Node.cs
+++ b/Scripts/Node.cs
@@ -57,12 +57,12 @@ namespace XNode {
public IEnumerable Outputs { get { foreach (NodePort port in Ports) { if (port.IsOutput) yield return port; } } }
/// Iterate over all inputs on this node.
public IEnumerable Inputs { get { foreach (NodePort port in Ports) { if (port.IsInput) yield return port; } } }
- /// Iterate over all instane ports on this node.
- public IEnumerable InstancePorts { get { foreach (NodePort port in Ports) { if (port.IsDynamic) yield return port; } } }
- /// Iterate over all instance outputs on this node.
- public IEnumerable InstanceOutputs { get { foreach (NodePort port in Ports) { if (port.IsDynamic && port.IsOutput) yield return port; } } }
- /// Iterate over all instance inputs on this node.
- public IEnumerable InstanceInputs { get { foreach (NodePort port in Ports) { if (port.IsDynamic && port.IsInput) yield return port; } } }
+ /// Iterate over all dynamic ports on this node.
+ public IEnumerable DynamicPorts { get { foreach (NodePort port in Ports) { if (port.IsDynamic) yield return port; } } }
+ /// Iterate over all dynamic outputs on this node.
+ public IEnumerable DynamicOutputs { get { foreach (NodePort port in Ports) { if (port.IsDynamic && port.IsOutput) yield return port; } } }
+ /// Iterate over all dynamic inputs on this node.
+ public IEnumerable DynamicInputs { get { foreach (NodePort port in Ports) { if (port.IsDynamic && port.IsInput) yield return port; } } }
/// Parent
[SerializeField] public NodeGraph graph;
/// Position on the
@@ -97,25 +97,25 @@ namespace XNode {
/// Convenience function.
///
///
- public NodePort AddInstanceInput(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);
+ public NodePort AddDynamicInput(Type type, Node.ConnectionType connectionType = Node.ConnectionType.Multiple, Node.TypeConstraint typeConstraint = TypeConstraint.None, string fieldName = null) {
+ return AddDynamicPort(type, NodePort.IO.Input, connectionType, typeConstraint, fieldName);
}
/// Convenience function.
///
///
- public NodePort AddInstanceOutput(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);
+ public NodePort AddDynamicOutput(Type type, Node.ConnectionType connectionType = Node.ConnectionType.Multiple, Node.TypeConstraint typeConstraint = TypeConstraint.None, string fieldName = null) {
+ return AddDynamicPort(type, NodePort.IO.Output, connectionType, typeConstraint, fieldName);
}
/// Add a dynamic, serialized port to this node.
- ///
- ///
- 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) {
- fieldName = "instanceInput_0";
+ fieldName = "dynamicInput_0";
int i = 0;
- while (HasPort(fieldName)) fieldName = "instanceInput_" + (++i);
+ while (HasPort(fieldName)) fieldName = "dynamicInput_" + (++i);
} else if (HasPort(fieldName)) {
Debug.LogWarning("Port '" + fieldName + "' already exists in " + name, this);
return ports[fieldName];
@@ -125,27 +125,27 @@ namespace XNode {
return port;
}
- /// Remove an instance port from the node
- public void RemoveInstancePort(string fieldName) {
- NodePort instancePort = GetPort(fieldName);
- if (instancePort == null) throw new ArgumentException("port " + fieldName + " doesn't exist");
- RemoveInstancePort(GetPort(fieldName));
+ /// Remove an dynamic port from the node
+ public void RemoveDynamicPort(string fieldName) {
+ NodePort dynamicPort = GetPort(fieldName);
+ if (dynamicPort == null) throw new ArgumentException("port " + fieldName + " doesn't exist");
+ RemoveDynamicPort(GetPort(fieldName));
}
- /// Remove an instance port from the node
- public void RemoveInstancePort(NodePort port) {
+ /// Remove an dynamic port from the node
+ public void RemoveDynamicPort(NodePort port) {
if (port == null) throw new ArgumentNullException("port");
else if (port.IsStatic) throw new ArgumentException("cannot remove static port");
port.ClearConnections();
ports.Remove(port.fieldName);
}
- /// Removes all instance ports from the node
- [ContextMenu("Clear Instance Ports")]
- public void ClearInstancePorts() {
- List instancePorts = new List(InstancePorts);
- foreach (NodePort port in instancePorts) {
- RemoveInstancePort(port);
+ /// Removes all dynamic ports from the node
+ [ContextMenu("Clear Dynamic Ports")]
+ public void ClearDynamicPorts() {
+ List dynamicPorts = new List(DynamicPorts);
+ foreach (NodePort port in dynamicPorts) {
+ RemoveDynamicPort(port);
}
}
#endregion
@@ -223,18 +223,18 @@ namespace XNode {
public class InputAttribute : Attribute {
public ShowBackingValue backingValue;
public ConnectionType connectionType;
- public bool instancePortList;
+ public bool dynamicPortList;
public TypeConstraint typeConstraint;
/// Mark a serializable field as an input port. You can access this through
/// Should we display the backing value for this port as an editor field?
/// Should we allow multiple connections?
/// Constrains which input connections can be made to this port
- /// If true, will display a reorderable list of inputs instead of a single port. Will automatically add and display values for lists and arrays
- public InputAttribute(ShowBackingValue backingValue = ShowBackingValue.Unconnected, ConnectionType connectionType = ConnectionType.Multiple, TypeConstraint typeConstraint = TypeConstraint.None, bool instancePortList = false) {
+ /// If true, will display a reorderable list of inputs instead of a single port. Will automatically add and display values for lists and arrays
+ public InputAttribute(ShowBackingValue backingValue = ShowBackingValue.Unconnected, ConnectionType connectionType = ConnectionType.Multiple, TypeConstraint typeConstraint = TypeConstraint.None, bool dynamicPortList = false) {
this.backingValue = backingValue;
this.connectionType = connectionType;
- this.instancePortList = instancePortList;
+ this.dynamicPortList = dynamicPortList;
this.typeConstraint = typeConstraint;
}
}
@@ -244,16 +244,16 @@ namespace XNode {
public class OutputAttribute : Attribute {
public ShowBackingValue backingValue;
public ConnectionType connectionType;
- public bool instancePortList;
+ public bool dynamicPortList;
/// Mark a serializable field as an output port. You can access this through
/// Should we display the backing value for this port as an editor field?
/// Should we allow multiple connections?
- /// If true, will display a reorderable list of outputs instead of a single port. Will automatically add and display values for lists and arrays
- public OutputAttribute(ShowBackingValue backingValue = ShowBackingValue.Never, ConnectionType connectionType = ConnectionType.Multiple, bool instancePortList = false) {
+ /// If true, will display a reorderable list of outputs instead of a single port. Will automatically add and display values for lists and arrays
+ public OutputAttribute(ShowBackingValue backingValue = ShowBackingValue.Never, ConnectionType connectionType = ConnectionType.Multiple, bool dynamicPortList = false) {
this.backingValue = backingValue;
this.connectionType = connectionType;
- this.instancePortList = instancePortList;
+ this.dynamicPortList = dynamicPortList;
}
}