Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save instance-id/7f59bcb20611022eb45d423607681325 to your computer and use it in GitHub Desktop.
Save instance-id/7f59bcb20611022eb45d423607681325 to your computer and use it in GitHub Desktop.
Fixes Unity editor viewport mousewheel
#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