Skip to content

Commit

Permalink
[FIX] fix a problem when a complex class with optional port drawing i…
Browse files Browse the repository at this point in the history
…s used with NodeEditorGUILayout.DynamicPortList. By having an item that wasn't drawing the port, the method was throwing a KeyNotFoundException when reordering. (#262)

The fix detects if there isn't a port when swapping rects.
  • Loading branch information
fdtdev authored May 9, 2020
1 parent 4c6d22a commit 8046e6e
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions Scripts/Editor/NodeEditorGUILayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,10 @@ private static ReorderableList CreateReorderableList(string fieldName, List<XNod
};
list.onReorderCallback =
(ReorderableList rl) => {

bool hasRect = false;
bool hasNewRect = false;
Rect rect = Rect.zero;
Rect newRect = Rect.zero;
// Move up
if (rl.index > reorderableListIndex) {
for (int i = reorderableListIndex; i < rl.index; ++i) {
Expand All @@ -380,9 +383,10 @@ private static ReorderableList CreateReorderableList(string fieldName, List<XNod
port.SwapConnections(nextPort);

// Swap cached positions to mitigate twitching
Rect rect = NodeEditorWindow.current.portConnectionPoints[port];
NodeEditorWindow.current.portConnectionPoints[port] = NodeEditorWindow.current.portConnectionPoints[nextPort];
NodeEditorWindow.current.portConnectionPoints[nextPort] = rect;
hasRect = NodeEditorWindow.current.portConnectionPoints.TryGetValue(port, out rect);
hasNewRect = NodeEditorWindow.current.portConnectionPoints.TryGetValue(nextPort, out newRect);
NodeEditorWindow.current.portConnectionPoints[port] = hasNewRect?newRect:rect;
NodeEditorWindow.current.portConnectionPoints[nextPort] = hasRect?rect:newRect;
}
}
// Move down
Expand All @@ -393,9 +397,10 @@ private static ReorderableList CreateReorderableList(string fieldName, List<XNod
port.SwapConnections(nextPort);

// Swap cached positions to mitigate twitching
Rect rect = NodeEditorWindow.current.portConnectionPoints[port];
NodeEditorWindow.current.portConnectionPoints[port] = NodeEditorWindow.current.portConnectionPoints[nextPort];
NodeEditorWindow.current.portConnectionPoints[nextPort] = rect;
hasRect = NodeEditorWindow.current.portConnectionPoints.TryGetValue(port, out rect);
hasNewRect = NodeEditorWindow.current.portConnectionPoints.TryGetValue(nextPort, out newRect);
NodeEditorWindow.current.portConnectionPoints[port] = hasNewRect?newRect:rect;
NodeEditorWindow.current.portConnectionPoints[nextPort] = hasRect?rect:newRect;
}
}
// Apply changes
Expand Down

0 comments on commit 8046e6e

Please sign in to comment.