Ok, even without being able to replicate this issue, I believe I have a solution…
private void ProcessEvents()
{
if (!position.Contains(Event.current.mousePosition))
{
draggingNode = null;
return;
}
if (Event.current.type == EventType.MouseDown && draggingNode == null)
{
draggingNode = GetNodeAtPoint(Event.current.mousePosition);
if (draggingNode != null)
{
dragginOffset = draggingNode.rect.position - Event.current.mousePosition;
}
}
else if (Event.current.type == EventType.MouseDrag && draggingNode != null)
{
Undo.RecordObject(selectedDialogue, "Move Dialogue Node");
draggingNode.rect.position = Event.current.mousePosition + dragginOffset;
GUI.changed = true;
GUI.FocusControl(null);
}
else if (Event.current.type == EventType.MouseUp && draggingNode != null)
{
draggingNode = null;
}
}
While OnMouseLeaveWindow only fires if no buttons are pressed (annoying that they did that, but I believe it’s to facilitate dragging from one window to another), you can always test the position of the mouse against the bounds of the window, which is stored in a field position
.
So
if (!position.Contains(Event.current.mousePosition))
{
draggingNode = null;
return;
}
should automatically reset draggingNode if the mouse leaves the boundary of the EditorWindow.