mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-20 17:26:02 +08:00
Fixed issues relating to InstancePortList
This commit is contained in:
parent
6783324018
commit
01d7f782e4
@ -301,7 +301,6 @@ namespace XNodeEditor {
|
|||||||
|
|
||||||
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> instancePorts, 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;
|
||||||
int arraySize = hasArrayData ? arrayData.arraySize : 0;
|
|
||||||
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(instancePorts, null, true, true, true, true);
|
||||||
string label = arrayData != null ? arrayData.displayName : ObjectNames.NicifyVariableName(fieldName);
|
string label = arrayData != null ? arrayData.displayName : ObjectNames.NicifyVariableName(fieldName);
|
||||||
@ -317,8 +316,10 @@ namespace XNodeEditor {
|
|||||||
SerializedProperty itemData = arrayData.GetArrayElementAtIndex(index);
|
SerializedProperty itemData = arrayData.GetArrayElementAtIndex(index);
|
||||||
EditorGUI.PropertyField(rect, itemData, true);
|
EditorGUI.PropertyField(rect, itemData, true);
|
||||||
} else EditorGUI.LabelField(rect, port.fieldName);
|
} else EditorGUI.LabelField(rect, port.fieldName);
|
||||||
|
if (port != null) {
|
||||||
Vector2 pos = rect.position + (port.IsOutput?new Vector2(rect.width + 6, 0) : new Vector2(-36, 0));
|
Vector2 pos = rect.position + (port.IsOutput?new Vector2(rect.width + 6, 0) : new Vector2(-36, 0));
|
||||||
NodeEditorGUILayout.PortField(pos, port);
|
NodeEditorGUILayout.PortField(pos, port);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
list.elementHeightCallback =
|
list.elementHeightCallback =
|
||||||
(int index) => {
|
(int index) => {
|
||||||
@ -391,11 +392,22 @@ namespace XNodeEditor {
|
|||||||
else node.AddInstanceInput(type, connectionType, typeConstraint, newName);
|
else node.AddInstanceInput(type, connectionType, typeConstraint, newName);
|
||||||
serializedObject.Update();
|
serializedObject.Update();
|
||||||
EditorUtility.SetDirty(node);
|
EditorUtility.SetDirty(node);
|
||||||
if (hasArrayData) arrayData.InsertArrayElementAtIndex(arraySize);
|
if (hasArrayData) {
|
||||||
|
arrayData.InsertArrayElementAtIndex(arrayData.arraySize);
|
||||||
|
}
|
||||||
serializedObject.ApplyModifiedProperties();
|
serializedObject.ApplyModifiedProperties();
|
||||||
};
|
};
|
||||||
list.onRemoveCallback =
|
list.onRemoveCallback =
|
||||||
(ReorderableList rl) => {
|
(ReorderableList rl) => {
|
||||||
|
|
||||||
|
Predicate<string> isMatchingInstancePort =
|
||||||
|
x => {
|
||||||
|
string[] split = x.Split(' ');
|
||||||
|
if (split != null && split.Length == 2) return split[0] == fieldName;
|
||||||
|
else return false;
|
||||||
|
};
|
||||||
|
instancePorts = node.InstancePorts.Where(x => isMatchingInstancePort(x.fieldName)).OrderBy(x => x.fieldName).ToList();
|
||||||
|
|
||||||
int index = rl.index;
|
int index = rl.index;
|
||||||
// Clear the removed ports connections
|
// Clear the removed ports connections
|
||||||
instancePorts[index].ClearConnections();
|
instancePorts[index].ClearConnections();
|
||||||
@ -413,23 +425,21 @@ namespace XNodeEditor {
|
|||||||
EditorUtility.SetDirty(node);
|
EditorUtility.SetDirty(node);
|
||||||
if (hasArrayData) {
|
if (hasArrayData) {
|
||||||
arrayData.DeleteArrayElementAtIndex(index);
|
arrayData.DeleteArrayElementAtIndex(index);
|
||||||
arraySize--;
|
|
||||||
// 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 <= arraySize) {
|
if (instancePorts.Count <= arrayData.arraySize) {
|
||||||
while (instancePorts.Count <= arraySize) {
|
while (instancePorts.Count <= arrayData.arraySize) {
|
||||||
arrayData.DeleteArrayElementAtIndex(--arraySize);
|
arrayData.DeleteArrayElementAtIndex(arrayData.arraySize - 1);
|
||||||
}
|
}
|
||||||
UnityEngine.Debug.LogWarning("Array size exceeded instance ports size. Excess items removed.");
|
UnityEngine.Debug.LogWarning("Array size exceeded instance ports size. Excess items removed.");
|
||||||
}
|
}
|
||||||
serializedObject.ApplyModifiedProperties();
|
serializedObject.ApplyModifiedProperties();
|
||||||
serializedObject.Update();
|
serializedObject.Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (hasArrayData) {
|
if (hasArrayData) {
|
||||||
int instancePortCount = instancePorts.Count;
|
int instancePortCount = instancePorts.Count;
|
||||||
while (instancePortCount < arraySize) {
|
while (instancePortCount < arrayData.arraySize) {
|
||||||
// Add instance port postfixed with an index number
|
// Add instance port postfixed with an index number
|
||||||
string newName = arrayData.name + " 0";
|
string newName = arrayData.name + " 0";
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@ -439,9 +449,8 @@ namespace XNodeEditor {
|
|||||||
EditorUtility.SetDirty(node);
|
EditorUtility.SetDirty(node);
|
||||||
instancePortCount++;
|
instancePortCount++;
|
||||||
}
|
}
|
||||||
while (arraySize < instancePortCount) {
|
while (arrayData.arraySize < instancePortCount) {
|
||||||
arrayData.InsertArrayElementAtIndex(arraySize);
|
arrayData.InsertArrayElementAtIndex(arrayData.arraySize);
|
||||||
arraySize++;
|
|
||||||
}
|
}
|
||||||
serializedObject.ApplyModifiedProperties();
|
serializedObject.ApplyModifiedProperties();
|
||||||
serializedObject.Update();
|
serializedObject.Update();
|
||||||
|
|||||||
@ -127,6 +127,8 @@ namespace XNode {
|
|||||||
|
|
||||||
/// <summary> Remove an instance port from the node </summary>
|
/// <summary> Remove an instance port from the node </summary>
|
||||||
public void RemoveInstancePort(string fieldName) {
|
public void RemoveInstancePort(string fieldName) {
|
||||||
|
NodePort instancePort = GetPort(fieldName);
|
||||||
|
if (instancePort == null) throw new ArgumentException("port " + fieldName + " doesn't exist");
|
||||||
RemoveInstancePort(GetPort(fieldName));
|
RemoveInstancePort(GetPort(fieldName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user