Last active
June 2, 2021 03:35
-
-
Save ArildF/5dc4ff3cb9f443a3d626ac278ec5f87b to your computer and use it in GitHub Desktop.
Blender scene camera controls for Unity
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
using UnityEditor; | |
using UnityEngine; | |
namespace Editor | |
{ | |
[InitializeOnLoad] | |
public class BlenderSceneCameraControls | |
{ | |
static BlenderSceneCameraControls() | |
{ | |
SceneView.duringSceneGui -= SceneViewOnDuringSceneGui; | |
SceneView.duringSceneGui += SceneViewOnDuringSceneGui; | |
} | |
private static void SceneViewOnDuringSceneGui(SceneView view) | |
{ | |
Event e = Event.current; | |
if (e?.type == EventType.KeyDown) | |
{ | |
var dir = e.control ? 1 : -1; | |
if (e.keyCode == KeyCode.Keypad1) | |
{ | |
SetSceneCamera(view, Vector3.forward * dir); | |
} | |
else if (e.keyCode == KeyCode.Keypad3) | |
{ | |
SetSceneCamera(view, Vector3.left * dir); | |
} | |
else if (e.keyCode == KeyCode.Keypad7) | |
{ | |
SetSceneCamera(view, Vector3.up * dir); | |
} | |
else if (e.keyCode == KeyCode.Keypad5) | |
{ | |
view.orthographic = !view.orthographic; | |
} | |
} | |
} | |
private static void SetSceneCamera(SceneView view, Vector3 direction) | |
{ | |
var target = view.pivot + direction; | |
view.LookAtDirect(target, Quaternion.LookRotation(direction)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Perfect, Thank you :) (Just had to change the namespace to some arbitrary name)