Skip to content

Instantly share code, notes, and snippets.

@ArildF
Last active June 2, 2021 03:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ArildF/5dc4ff3cb9f443a3d626ac278ec5f87b to your computer and use it in GitHub Desktop.
Save ArildF/5dc4ff3cb9f443a3d626ac278ec5f87b to your computer and use it in GitHub Desktop.
Blender scene camera controls for Unity
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));
}
}
}
@SDSDInk
Copy link

SDSDInk commented Jun 2, 2021

Perfect, Thank you :) (Just had to change the namespace to some arbitrary name)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment