Last active
September 21, 2019 16:42
-
-
Save yasirkula/8772bfe971d0b4836b1f7bfcb1f9cded to your computer and use it in GitHub Desktop.
"Right mouse button+Scroll wheel" will continue to zoom in/zoom out the Scene View instead of changing the camera speed on Unity 2019+
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if UNITY_2019_1_OR_NEWER | |
using UnityEditor; | |
using UnityEngine; | |
[InitializeOnLoad] | |
public class EditorCameraZoomWithScrollWheel | |
{ | |
private const float CAMERA_SPEED = -0.25f; | |
private static bool rmbDown = false; | |
static EditorCameraZoomWithScrollWheel() | |
{ | |
SceneView.beforeSceneGui -= OnScene; | |
SceneView.beforeSceneGui += OnScene; | |
} | |
private static void OnScene( SceneView scene ) | |
{ | |
Event e = Event.current; | |
if( e.isMouse && e.button == 1 ) | |
{ | |
if( e.type == EventType.MouseDown ) | |
rmbDown = true; | |
else if( e.type == EventType.MouseUp ) | |
rmbDown = false; | |
} | |
if( e.isScrollWheel && rmbDown ) | |
{ | |
Vector3 pivot = scene.pivot; | |
pivot += scene.camera.transform.forward * ( e.delta.y * CAMERA_SPEED ); | |
scene.pivot = pivot; | |
e.Use(); | |
} | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sweet baby jesus, thank you for this!