Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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