mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-20 01:06:01 +08:00
[FIX] fix a problem when a complex class with optional port drawing is 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.
This commit is contained in:
parent
4c6d22a152
commit
8046e6e0bf
@ -371,7 +371,10 @@ namespace XNodeEditor {
|
||||
};
|
||||
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) {
|
||||
@ -380,9 +383,10 @@ namespace XNodeEditor {
|
||||
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
|
||||
@ -393,9 +397,10 @@ namespace XNodeEditor {
|
||||
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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user