mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-21 17:56:06 +08:00
Improved InstancePortList. It now takes a NodePort.IO parameter
This commit is contained in:
parent
372c968c85
commit
f9e024198e
@ -190,22 +190,34 @@ namespace XNodeEditor {
|
|||||||
GUI.color = col;
|
GUI.color = col;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Obsolete("Use InstancePortList(string, Type, SerializedObject, NodePort.IO, Node.ConnectionType) instead")]
|
||||||
|
public static void InstancePortList(string fieldName, Type type, SerializedObject serializedObject, XNode.Node.ConnectionType connectionType = XNode.Node.ConnectionType.Multiple) {
|
||||||
|
InstancePortList(fieldName, type, serializedObject, XNode.NodePort.IO.Output, connectionType);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary> Draw an editable list of instance ports. Port names are named as "[fieldName] [index]" </summary>
|
/// <summary> Draw an editable list of instance 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 instance 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 instance ports</param>
|
||||||
public static void InstancePortList(string fieldName, Type type, SerializedObject serializedObject, XNode.Node.ConnectionType connectionType = XNode.Node.ConnectionType.Multiple) {
|
public static void InstancePortList(string fieldName, Type type, SerializedObject serializedObject, XNode.NodePort.IO io, XNode.Node.ConnectionType connectionType = XNode.Node.ConnectionType.Multiple) {
|
||||||
XNode.Node node = serializedObject.targetObject as XNode.Node;
|
XNode.Node node = serializedObject.targetObject as XNode.Node;
|
||||||
SerializedProperty arrayData = serializedObject.FindProperty(fieldName);
|
SerializedProperty arrayData = serializedObject.FindProperty(fieldName);
|
||||||
bool hasArrayData = arrayData != null && arrayData.isArray;
|
bool hasArrayData = arrayData != null && arrayData.isArray;
|
||||||
int arraySize = hasArrayData ? arrayData.arraySize : 0;
|
int arraySize = hasArrayData ? arrayData.arraySize : 0;
|
||||||
|
|
||||||
List<XNode.NodePort> instancePorts = node.InstancePorts.Where(x => x.fieldName.StartsWith(fieldName)).OrderBy(x => x.fieldName).ToList();
|
Predicate<string> isMatchingInstancePort =
|
||||||
|
x => {
|
||||||
|
string[] split = x.Split(' ');
|
||||||
|
if (split != null && split.Length == 2) return split[0] == fieldName;
|
||||||
|
else return false;
|
||||||
|
};
|
||||||
|
List<XNode.NodePort> instancePorts = node.InstancePorts.Where(x => isMatchingInstancePort(x.fieldName)).OrderBy(x => x.fieldName).ToList();
|
||||||
|
|
||||||
for (int i = 0; i < instancePorts.Count(); i++) {
|
for (int i = 0; i < instancePorts.Count(); i++) {
|
||||||
GUILayout.BeginHorizontal();
|
GUILayout.BeginHorizontal();
|
||||||
if (GUILayout.Button("-", GUILayout.Width(30))) {
|
// 'Remove' button
|
||||||
|
if (GUILayout.Button("-", GUILayout.Width(20))) {
|
||||||
// Clear the removed ports connections
|
// Clear the removed ports connections
|
||||||
instancePorts[i].ClearConnections();
|
instancePorts[i].ClearConnections();
|
||||||
// Move following connections one step up to replace the missing connection
|
// Move following connections one step up to replace the missing connection
|
||||||
@ -234,6 +246,7 @@ namespace XNodeEditor {
|
|||||||
serializedObject.Update();
|
serializedObject.Update();
|
||||||
}
|
}
|
||||||
i--;
|
i--;
|
||||||
|
GUILayout.EndHorizontal();
|
||||||
} else {
|
} else {
|
||||||
if (hasArrayData) {
|
if (hasArrayData) {
|
||||||
if (i < arraySize) {
|
if (i < arraySize) {
|
||||||
@ -245,19 +258,23 @@ namespace XNodeEditor {
|
|||||||
} else {
|
} else {
|
||||||
EditorGUILayout.LabelField(instancePorts[i].fieldName);
|
EditorGUILayout.LabelField(instancePorts[i].fieldName);
|
||||||
}
|
}
|
||||||
NodeEditorGUILayout.PortField(new GUIContent(), node.GetPort(instancePorts[i].fieldName), GUILayout.Width(-4));
|
|
||||||
|
GUILayout.EndHorizontal();
|
||||||
|
NodeEditorGUILayout.AddPortField(node.GetPort(instancePorts[i].fieldName));
|
||||||
}
|
}
|
||||||
GUILayout.EndHorizontal();
|
// GUILayout.EndHorizontal();
|
||||||
}
|
}
|
||||||
GUILayout.BeginHorizontal();
|
GUILayout.BeginHorizontal();
|
||||||
EditorGUILayout.Space();
|
GUILayout.FlexibleSpace();
|
||||||
if (GUILayout.Button("+", GUILayout.Width(30))) {
|
// 'Add' button
|
||||||
|
if (GUILayout.Button("+", GUILayout.Width(20))) {
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
node.AddInstanceOutput(type, connectionType, newName);
|
if (io == XNode.NodePort.IO.Output) node.AddInstanceOutput(type, connectionType, newName);
|
||||||
|
else node.AddInstanceInput(type, connectionType, newName);
|
||||||
serializedObject.Update();
|
serializedObject.Update();
|
||||||
EditorUtility.SetDirty(node);
|
EditorUtility.SetDirty(node);
|
||||||
if (hasArrayData) arrayData.InsertArrayElementAtIndex(arraySize);
|
if (hasArrayData) arrayData.InsertArrayElementAtIndex(arraySize);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user