Created
May 3, 2020 21:32
-
-
Save instance-id/7f59bcb20611022eb45d423607681325 to your computer and use it in GitHub Desktop.
Fixes Unity editor viewport mousewheel
This file contains 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