diff --git a/Scripts/Brushes/CompoundBrushes/Editor/ShapeEditorWindow.cs b/Scripts/Brushes/CompoundBrushes/Editor/ShapeEditorWindow.cs index da4f2fd1..b862aab7 100644 --- a/Scripts/Brushes/CompoundBrushes/Editor/ShapeEditorWindow.cs +++ b/Scripts/Brushes/CompoundBrushes/Editor/ShapeEditorWindow.cs @@ -42,8 +42,16 @@ public class ShapeEditorWindow : EditorWindow /// private int gridScale = 16; + /// + /// The mouse position while dragging to calculate relative positioning. + /// private Vector2Int mouseDragLastGridPosition = new Vector2Int(); + /// + /// Whether the current drag is valid (invalid if sliding from the toolbar onto the grid). + /// + private bool isValidDrag = false; + /// /// The currently selected objects. /// @@ -248,6 +256,9 @@ private void OnGUI() // move object around with the left mouse button. if (Event.current.button == 0) { + // can't slide from the toolbar onto the grid. + if (!isValidDrag) return; + Vector2Int grid = ScreenPointToGrid(new Vector3(Event.current.mousePosition.x, Event.current.mousePosition.y)); if (GetViewportRect().Contains(Event.current.mousePosition)) { @@ -321,25 +332,33 @@ private void OnGUI() if (Event.current.type == EventType.MouseDown) { - if (Event.current.button == 0 && GetViewportRect().Contains(Event.current.mousePosition)) + if (Event.current.button == 0) { - // if the user is not holding CTRL or SHIFT we clear the selected objects. - if ((Event.current.modifiers & EventModifiers.Control) == 0 && (Event.current.modifiers & EventModifiers.Shift) == 0) - selectedObjects.Clear(); + isValidDrag = false; - // try finding an object under the mouse cursor. - Vector2Int grid = ScreenPointToGrid(new Vector3(Event.current.mousePosition.x, Event.current.mousePosition.y)); - ISelectable found = GetObjectAtGridPosition(grid); - // if the object was already selected, deselect it. - if (found != null && selectedObjects.Contains(found)) - // deselect the object. - selectedObjects.Remove(found); - else if (found != null && !selectedObjects.Contains(found)) - // select the object. - selectedObjects.Add(found); - // store the grid position for relative dragging. - mouseDragLastGridPosition = grid; - this.Repaint(); + if (GetViewportRect().Contains(Event.current.mousePosition)) + { + // the user did not click on the toolbar so dragging is valid. + isValidDrag = true; + + // if the user is not holding CTRL or SHIFT we clear the selected objects. + if ((Event.current.modifiers & EventModifiers.Control) == 0 && (Event.current.modifiers & EventModifiers.Shift) == 0) + selectedObjects.Clear(); + + // try finding an object under the mouse cursor. + Vector2Int grid = ScreenPointToGrid(new Vector3(Event.current.mousePosition.x, Event.current.mousePosition.y)); + ISelectable found = GetObjectAtGridPosition(grid); + // if the object was already selected, deselect it. + if (found != null && selectedObjects.Contains(found)) + // deselect the object. + selectedObjects.Remove(found); + else if (found != null && !selectedObjects.Contains(found)) + // select the object. + selectedObjects.Add(found); + // store the grid position for relative dragging. + mouseDragLastGridPosition = grid; + this.Repaint(); + } } }