Skip to content

Commit d7d6f56

Browse files
authored
Mouse Cursor Tweaks (#376)
Fixes mouse cursor bugs + culled related duplicate and unnecessary code.
1 parent 9f25003 commit d7d6f56

File tree

3 files changed

+67
-68
lines changed

3 files changed

+67
-68
lines changed

Plugins/Editor/Scripts/View/GUI/EditModeGUI/EditModes/EditMode.Edit.cs

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,15 @@ private bool UpdateSelection(bool allowSubstraction = true)
361361

362362

363363
private MouseCursor _currentCursor = MouseCursor.Arrow;
364+
private void UpdateMouseCursor()
365+
{
366+
if (GUIUtility.hotControl == _rectSelectionId &&
367+
!_movePlaneInNormalDirection &&
368+
GUIUtility.hotControl != 0)
369+
return;
370+
371+
_currentCursor = CursorUtility.GetSelectionCursor(SelectionUtility.GetEventSelectionType());
372+
}
364373

365374
private EditMode SetHoverOn(EditMode editModeType, int target, int index = -1)
366375
{
@@ -379,34 +388,22 @@ private EditMode SetHoverOn(EditMode editModeType, int target, int index = -1)
379388
if (index == -1)
380389
return EditMode.None;
381390

382-
var newCursor = MouseCursor.Arrow;
383391
switch (editModeType)
384392
{
385-
case EditMode.RotateEdge: _hoverOnEdgeIndex = index; newCursor = MouseCursor.RotateArrow; break;
386-
case EditMode.MovingEdge: _hoverOnEdgeIndex = index; newCursor = MouseCursor.MoveArrow; break;
387-
case EditMode.MovingPoint: _hoverOnPointIndex = index; newCursor = MouseCursor.MoveArrow; break;
388-
case EditMode.MovingPolygon: _hoverOnPolygonIndex = index; newCursor = MouseCursor.MoveArrow; break;
393+
case EditMode.RotateEdge: _hoverOnEdgeIndex = index; break;
394+
case EditMode.MovingEdge: _hoverOnEdgeIndex = index; break;
395+
case EditMode.MovingPoint: _hoverOnPointIndex = index; break;
396+
case EditMode.MovingPolygon: _hoverOnPolygonIndex = index; break;
389397
}
390398

391-
if (_currentCursor == MouseCursor.Arrow)
392-
_currentCursor = newCursor;
393-
394399
return editModeType;
395400
}
396-
private void UpdateMouseCursor()
397-
{
398-
if (GUIUtility.hotControl == _rectSelectionId &&
399-
!_movePlaneInNormalDirection &&
400-
GUIUtility.hotControl != 0)
401-
return;
402401

403-
_currentCursor = CursorUtility.GetSelectionCursor(SelectionUtility.GetEventSelectionType());
404-
}
405-
406402
private EditMode HoverOnPoint(ControlMeshState meshState, int brushNodeIndex, int pointIndex)
407403
{
408404
var editMode = SetHoverOn(EditMode.MovingPoint, brushNodeIndex, pointIndex);
409405
meshState.Selection.Points[pointIndex] |= SelectState.Hovering;
406+
_currentCursor = MouseCursor.MoveArrow;
410407

411408
return editMode;
412409
}
@@ -471,7 +468,10 @@ private EditMode HoverOnEdge(ControlMeshState meshState, int brushIndex, int edg
471468
_currentCursor = CursorUtility.GetCursorForEdge(delta);
472469
} else
473470
if (Tools.current == Tool.Rotate)
471+
{
474472
editMode = SetHoverOn(EditMode.RotateEdge, brushIndex, edgeIndex);
473+
_currentCursor = MouseCursor.RotateArrow;
474+
}
475475

476476
meshState.Selection.Edges[edgeIndex] |= SelectState.Hovering;
477477
return editMode;
@@ -1189,13 +1189,18 @@ private void OnPaint(SceneView sceneView)
11891189
_currentCursor = CursorUtility.GetCursorForDirection(_movePolygonDirection, 90);
11901190
}
11911191

1192-
{
1193-
if (sceneView != null)
1194-
{
1195-
var windowRect = new Rect(0, 0, sceneView.position.width, sceneView.position.height - CSG_GUIStyleUtility.BottomToolBarHeight);
1196-
EditorGUIUtility.AddCursorRect(windowRect, _currentCursor);
1197-
}
1198-
}
1192+
if (sceneView != null)
1193+
{
1194+
#if UNITY_2020_2_OR_NEWER
1195+
if (!Tools.viewToolActive)
1196+
#else
1197+
if (Tools.current != Tool.View && !Event.current.alt && Event.current.button != 1 && Event.current.button != 2)
1198+
#endif
1199+
{
1200+
var windowRect = new Rect(0, 0, sceneView.position.width, sceneView.position.height - CSG_GUIStyleUtility.BottomToolBarHeight);
1201+
EditorGUIUtility.AddCursorRect(windowRect, _currentCursor);
1202+
}
1203+
}
11991204

12001205
var origMatrix = Handles.matrix;
12011206
Handles.matrix = MathConstants.identityMatrix;

Plugins/Editor/Scripts/View/GUI/EditModeGUI/EditModes/EditMode.Place.cs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,14 +1119,7 @@ void MoveBoundsEdge(Camera camera, int edgeCenter, Vector3 offset, out Vector3 s
11191119
MouseCursor currentCursor = MouseCursor.Arrow;
11201120
void UpdateMouseCursor()
11211121
{
1122-
switch (SelectionUtility.GetEventSelectionType())
1123-
{
1124-
case SelectionType.Additive: currentCursor = MouseCursor.ArrowPlus; break;
1125-
case SelectionType.Subtractive: currentCursor = MouseCursor.ArrowMinus; break;
1126-
case SelectionType.Toggle: currentCursor = MouseCursor.Arrow; break;
1127-
1128-
default: currentCursor = MouseCursor.Arrow; break;
1129-
}
1122+
currentCursor = CursorUtility.GetSelectionCursor(SelectionUtility.GetEventSelectionType());
11301123
}
11311124

11321125
[NonSerialized] bool ignorePivotChange = false;
@@ -1359,10 +1352,9 @@ public void HandleEvents(SceneView sceneView, Rect sceneRect)
13591352
var inCamera = (camera != null) && camera.pixelRect.Contains(Event.current.mousePosition);
13601353

13611354
var originalEventType = Event.current.type;
1362-
if( Event.current.type == EventType.MouseMove ) { sceneView.Repaint(); }
1363-
else if (originalEventType == EventType.MouseMove) { mouseIsDragging = false; draggingOnCamera = null; realMousePosition = Event.current.mousePosition; }
1364-
else if (originalEventType == EventType.MouseDown) { mouseIsDragging = false; draggingOnCamera = camera; realMousePosition = prevMousePos = Event.current.mousePosition; }
1365-
else if (originalEventType == EventType.MouseUp) { draggingOnCamera = null; }
1355+
if (originalEventType == EventType.MouseMove) { mouseIsDragging = false; draggingOnCamera = null; realMousePosition = Event.current.mousePosition; }
1356+
else if (originalEventType == EventType.MouseDown) { mouseIsDragging = false; draggingOnCamera = camera; realMousePosition = prevMousePos = Event.current.mousePosition; }
1357+
else if (originalEventType == EventType.MouseUp) { draggingOnCamera = null; }
13661358
else if (originalEventType == EventType.MouseDrag)
13671359
{
13681360
if (!mouseIsDragging && (prevMousePos - Event.current.mousePosition).magnitude > 4.0f)
@@ -1393,13 +1385,18 @@ public void HandleEvents(SceneView sceneView, Rect sceneRect)
13931385
{
13941386
if (!SceneDragToolManager.IsDraggingObjectInScene)
13951387
{
1396-
{
1397-
if (sceneView)
1398-
{
1399-
var windowRect = new Rect(0, 0, sceneView.position.width, sceneView.position.height - CSG_GUIStyleUtility.BottomToolBarHeight);
1400-
EditorGUIUtility.AddCursorRect(windowRect, currentCursor);
1401-
}
1402-
}
1388+
if (sceneView)
1389+
{
1390+
#if UNITY_2020_2_OR_NEWER
1391+
if (!Tools.viewToolActive)
1392+
#else
1393+
if (Tools.current != Tool.View && !Event.current.alt && Event.current.button != 1 && Event.current.button != 2)
1394+
#endif
1395+
{
1396+
var windowRect = new Rect(0, 0, sceneView.position.width, sceneView.position.height - CSG_GUIStyleUtility.BottomToolBarHeight);
1397+
EditorGUIUtility.AddCursorRect(windowRect, currentCursor);
1398+
}
1399+
}
14031400

14041401
if (!mouseIsDragging &&
14051402
(toolEditMode == ToolEditMode.MovingObject ||

Plugins/Editor/Scripts/View/GUI/EditModeGUI/EditModes/EditMode.Surface.cs

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -470,22 +470,15 @@ EditMode SetHoverOn(EditMode editModeType, int target, int index = -1)
470470
hoverOnSurfaceIndex = index;
471471
return editModeType;
472472
}
473-
474-
MouseCursor currentCursor = MouseCursor.Arrow;
475-
void UpdateMouseCursor()
476-
{
477-
if (mouseIsDown)
478-
return;
479-
480-
switch (SelectionUtility.GetEventSelectionType())
481-
{
482-
case SelectionType.Additive: currentCursor = MouseCursor.ArrowPlus; break;
483-
case SelectionType.Subtractive: currentCursor = MouseCursor.ArrowMinus; break;
484-
case SelectionType.Toggle: currentCursor = MouseCursor.Arrow; break;
485473

486-
default: currentCursor = MouseCursor.Arrow; break;
487-
}
488-
}
474+
MouseCursor currentCursor = MouseCursor.Arrow;
475+
void UpdateMouseCursor()
476+
{
477+
if (mouseIsDown)
478+
return;
479+
480+
currentCursor = CursorUtility.GetSelectionCursor(SelectionUtility.GetEventSelectionType());
481+
}
489482

490483
bool UpdateGrid(Camera camera)
491484
{
@@ -1132,10 +1125,16 @@ public void HandleEvents(SceneView sceneView, Rect sceneRect)
11321125

11331126
if (sceneView != null)
11341127
{
1135-
var windowRect = new Rect(0, 0, sceneView.position.width, sceneView.position.height - CSG_GUIStyleUtility.BottomToolBarHeight);
1136-
if (currentCursor != MouseCursor.Arrow)
1137-
EditorGUIUtility.AddCursorRect(windowRect, currentCursor);
1138-
}
1128+
#if UNITY_2020_2_OR_NEWER
1129+
if (!Tools.viewToolActive)
1130+
#else
1131+
if (Tools.current != Tool.View && !Event.current.alt && Event.current.button != 1 && Event.current.button != 2)
1132+
#endif
1133+
{
1134+
var windowRect = new Rect(0, 0, sceneView.position.width, sceneView.position.height - CSG_GUIStyleUtility.BottomToolBarHeight);
1135+
if (currentCursor != MouseCursor.Arrow) EditorGUIUtility.AddCursorRect(windowRect, currentCursor);
1136+
}
1137+
}
11391138

11401139
if (currentControl == -1 ||
11411140
currentControl == surfaceSelectPaintControl)
@@ -1339,14 +1338,12 @@ public void HandleEvents(SceneView sceneView, Rect sceneRect)
13391338
}
13401339
}
13411340
}
1341+
if (!repaint)
13421342
{
1343-
if (!repaint)
1343+
for (int p = 0; p < surfaceState.surfaceSelectState.Length; p++)
13441344
{
1345-
for (int p = 0; p < surfaceState.surfaceSelectState.Length; p++)
1346-
{
1347-
if (surfaceState.surfaceSelectState[p] != oldSurfaceStates[p] || oldSurfaceStates[p] == SelectState.None)
1348-
repaint = true;
1349-
}
1345+
if (surfaceState.surfaceSelectState[p] != oldSurfaceStates[p] || oldSurfaceStates[p] == SelectState.None)
1346+
repaint = true;
13501347
}
13511348
}
13521349
}

0 commit comments

Comments
 (0)