mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-21 01:36:03 +08:00
Reordering improved, still WIP
This commit is contained in:
parent
4516293214
commit
82627812d6
@ -11,7 +11,7 @@ namespace XNodeEditor {
|
|||||||
public static class NodeEditorGUILayout {
|
public static class NodeEditorGUILayout {
|
||||||
|
|
||||||
private static readonly Dictionary<UnityEngine.Object, Dictionary<string, ReorderableList>> reorderableListCache = new Dictionary<UnityEngine.Object, Dictionary<string, ReorderableList>>();
|
private static readonly Dictionary<UnityEngine.Object, Dictionary<string, ReorderableList>> reorderableListCache = new Dictionary<UnityEngine.Object, Dictionary<string, ReorderableList>>();
|
||||||
|
private static int reorderableListIndex = -1;
|
||||||
/// <summary> Make a field for a serialized property. Automatically displays relevant node port. </summary>
|
/// <summary> Make a field for a serialized property. Automatically displays relevant node port. </summary>
|
||||||
public static void PropertyField(SerializedProperty property, bool includeChildren = true, params GUILayoutOption[] options) {
|
public static void PropertyField(SerializedProperty property, bool includeChildren = true, params GUILayoutOption[] options) {
|
||||||
PropertyField(property, (GUIContent) null, includeChildren, options);
|
PropertyField(property, (GUIContent) null, includeChildren, options);
|
||||||
@ -278,17 +278,42 @@ namespace XNodeEditor {
|
|||||||
(Rect rect) => {
|
(Rect rect) => {
|
||||||
EditorGUI.LabelField(rect, serializedObject.FindProperty(fieldName).displayName);
|
EditorGUI.LabelField(rect, serializedObject.FindProperty(fieldName).displayName);
|
||||||
};
|
};
|
||||||
|
list.onSelectCallback =
|
||||||
|
(ReorderableList rl) => {
|
||||||
|
reorderableListIndex = rl.index;
|
||||||
|
};
|
||||||
list.onReorderCallback =
|
list.onReorderCallback =
|
||||||
(ReorderableList rl) => {
|
(ReorderableList rl) => {
|
||||||
for (int i = 0; i < rl.list.Count; i++) {
|
if (hasArrayData) {
|
||||||
XNode.NodePort port = rl.list[i] as XNode.NodePort;
|
SerializedProperty arrayDataOriginal = arrayData.Copy();
|
||||||
string[] name = port.fieldName.Split(' ');
|
arrayData.MoveArrayElement(reorderableListIndex, rl.index);
|
||||||
int newIndex = int.Parse(name[1]);
|
|
||||||
if (i != newIndex) {
|
}
|
||||||
//port.Rename(name[0] + " " + i);
|
List<XNode.NodePort> fromConnections = (rl.list[reorderableListIndex] as XNode.NodePort).GetConnections();
|
||||||
Debug.Log("Switch " + i + " and " + newIndex + "!");
|
for (int i = 0; i < rl.list.Count - 1; ++i) {
|
||||||
|
if (i >= reorderableListIndex) {
|
||||||
|
XNode.NodePort port = rl.list[i] as XNode.NodePort;
|
||||||
|
port.ClearConnections();
|
||||||
|
List<XNode.NodePort> newConnections = (rl.list[i + 1] as XNode.NodePort).GetConnections();
|
||||||
|
foreach (var c in newConnections) port.Connect(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
for (int i = rl.list.Count - 1; i > 0; --i) {
|
||||||
|
if (i > rl.index) {
|
||||||
|
XNode.NodePort port = rl.list[i] as XNode.NodePort;
|
||||||
|
port.ClearConnections();
|
||||||
|
List<XNode.NodePort> newConnections = (rl.list[i - 1] as XNode.NodePort).GetConnections();
|
||||||
|
foreach (var c in newConnections) port.Connect(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
XNode.NodePort toPort = rl.list[rl.index] as XNode.NodePort;
|
||||||
|
toPort.ClearConnections();
|
||||||
|
foreach (var c in fromConnections) toPort.Connect(c);
|
||||||
|
|
||||||
|
serializedObject.ApplyModifiedProperties();
|
||||||
|
serializedObject.Update();
|
||||||
|
NodeEditorWindow.current.Repaint();
|
||||||
};
|
};
|
||||||
list.onAddCallback =
|
list.onAddCallback =
|
||||||
(ReorderableList rl) => {
|
(ReorderableList rl) => {
|
||||||
|
|||||||
@ -202,6 +202,15 @@ namespace XNode {
|
|||||||
port.node.OnCreateConnection(this, port);
|
port.node.OnCreateConnection(this, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<NodePort> GetConnections() {
|
||||||
|
List<NodePort> result = new List<NodePort>();
|
||||||
|
for (int i = 0; i < connections.Count; i++) {
|
||||||
|
NodePort port = GetConnection(i);
|
||||||
|
if (port != null) result.Add(port);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public NodePort GetConnection(int i) {
|
public NodePort GetConnection(int i) {
|
||||||
//If the connection is broken for some reason, remove it.
|
//If the connection is broken for some reason, remove it.
|
||||||
if (connections[i].node == null || string.IsNullOrEmpty(connections[i].fieldName)) {
|
if (connections[i].node == null || string.IsNullOrEmpty(connections[i].fieldName)) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user