33// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
44
55using UnityEngine ;
6- using UnityEditor ;
6+ using UnityEditor . ShortcutManagement ;
77
88namespace UnityEditor
99{
1010 internal class VertexSnapping
1111 {
1212 private static Vector3 s_VertexSnappingOffset = Vector3 . zero ;
1313
14- // This method handles KeyUp, KeyDown and MouseMove for doing vertex snapping.
14+ [ Shortcut ( "Scene View/Toggle Vertex Snapping" , typeof ( SceneView ) , "#v" ) ]
15+ private static void ToggleVertexSnappingViaShortcut ( )
16+ {
17+ int id = GUIUtility . hotControl ;
18+ if ( Tools . vertexDragging )
19+ DisableVertexSnapping ( id ) ;
20+ else
21+ EnableVertexSnapping ( id ) ;
22+ }
23+
24+ [ ClutchShortcut ( "Scene View/Vertex Snapping" , typeof ( SceneView ) , "v" ) ]
25+ private static void ToggleVertexSnappingViaClutchShortcut ( ShortcutArguments arguments )
26+ {
27+ int id = GUIUtility . hotControl ;
28+ if ( arguments . state == ShortcutState . Begin )
29+ EnableVertexSnapping ( id ) ;
30+ else
31+ DisableVertexSnapping ( id ) ;
32+ }
33+
34+ // This method handles MouseMove for doing vertex snapping.
1535 // To ensure correct behaviour the caller must do on it's own:
1636 // - On MouseDown and MouseUp (if event is ours to use):
1737 // HandleUtility.ignoreRaySnapObjects = null;
@@ -29,52 +49,13 @@ internal class VertexSnapping
2949 //
3050 // This is not the most elegant code-reuse solution,
3151 // but still a step up from the copy-pasted code that was used before.
32- public static void HandleKeyAndMouseMove ( int id )
52+ public static void HandleMouseMove ( int id )
3353 {
34- Event evt = Event . current ;
35- switch ( evt . GetTypeForControl ( id ) )
54+ var evt = Event . current ;
55+ if ( evt . GetTypeForControl ( id ) == EventType . MouseMove && Tools . vertexDragging )
3656 {
37- case EventType . MouseMove :
38- {
39- if ( Tools . vertexDragging )
40- {
41- EnableVertexSnapping ( id ) ;
42- evt . Use ( ) ;
43- }
44- break ;
45- }
46- case EventType . KeyDown :
47- {
48- // Vertex selection
49- if ( ! EditorGUIUtility . editingTextField && evt . keyCode == KeyCode . V )
50- {
51- // We are searching for a vertex in our selection
52- if ( ! Tools . vertexDragging && ! evt . shift )
53- EnableVertexSnapping ( id ) ;
54-
55- evt . Use ( ) ;
56- }
57- break ;
58- }
59- case EventType . KeyUp :
60- {
61- // Vertex selection
62- if ( ! EditorGUIUtility . editingTextField && evt . keyCode == KeyCode . V )
63- {
64- if ( evt . shift )
65- Tools . vertexDragging = ! Tools . vertexDragging ; // toggle vertex dragging
66- else if ( Tools . vertexDragging )
67- Tools . vertexDragging = false ; // stop vertex dragging
68-
69- if ( Tools . vertexDragging )
70- EnableVertexSnapping ( id ) ;
71- else
72- DisableVertexSnapping ( id ) ;
73-
74- evt . Use ( ) ;
75- }
76- break ;
77- }
57+ EnableVertexSnapping ( id ) ;
58+ evt . Use ( ) ;
7859 }
7960 }
8061
0 commit comments