mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-21 01:36:03 +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 =
|
list.onReorderCallback =
|
||||||
(ReorderableList rl) => {
|
(ReorderableList rl) => {
|
||||||
|
bool hasRect = false;
|
||||||
|
bool hasNewRect = false;
|
||||||
|
Rect rect = Rect.zero;
|
||||||
|
Rect newRect = Rect.zero;
|
||||||
// Move up
|
// Move up
|
||||||
if (rl.index > reorderableListIndex) {
|
if (rl.index > reorderableListIndex) {
|
||||||
for (int i = reorderableListIndex; i < rl.index; ++i) {
|
for (int i = reorderableListIndex; i < rl.index; ++i) {
|
||||||
@ -380,9 +383,10 @@ namespace XNodeEditor {
|
|||||||
port.SwapConnections(nextPort);
|
port.SwapConnections(nextPort);
|
||||||
|
|
||||||
// Swap cached positions to mitigate twitching
|
// Swap cached positions to mitigate twitching
|
||||||
Rect rect = NodeEditorWindow.current.portConnectionPoints[port];
|
hasRect = NodeEditorWindow.current.portConnectionPoints.TryGetValue(port, out rect);
|
||||||
NodeEditorWindow.current.portConnectionPoints[port] = NodeEditorWindow.current.portConnectionPoints[nextPort];
|
hasNewRect = NodeEditorWindow.current.portConnectionPoints.TryGetValue(nextPort, out newRect);
|
||||||
NodeEditorWindow.current.portConnectionPoints[nextPort] = rect;
|
NodeEditorWindow.current.portConnectionPoints[port] = hasNewRect?newRect:rect;
|
||||||
|
NodeEditorWindow.current.portConnectionPoints[nextPort] = hasRect?rect:newRect;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Move down
|
// Move down
|
||||||
@ -393,9 +397,10 @@ namespace XNodeEditor {
|
|||||||
port.SwapConnections(nextPort);
|
port.SwapConnections(nextPort);
|
||||||
|
|
||||||
// Swap cached positions to mitigate twitching
|
// Swap cached positions to mitigate twitching
|
||||||
Rect rect = NodeEditorWindow.current.portConnectionPoints[port];
|
hasRect = NodeEditorWindow.current.portConnectionPoints.TryGetValue(port, out rect);
|
||||||
NodeEditorWindow.current.portConnectionPoints[port] = NodeEditorWindow.current.portConnectionPoints[nextPort];
|
hasNewRect = NodeEditorWindow.current.portConnectionPoints.TryGetValue(nextPort, out newRect);
|
||||||
NodeEditorWindow.current.portConnectionPoints[nextPort] = rect;
|
NodeEditorWindow.current.portConnectionPoints[port] = hasNewRect?newRect:rect;
|
||||||
|
NodeEditorWindow.current.portConnectionPoints[nextPort] = hasRect?rect:newRect;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Apply changes
|
// Apply changes
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user