How do you switch between front, side, top, down view from keyboard
Hi guys.
How do you switch between different views in the viewport by using the keyboard? I know that you can use the gizmo axis, but to click over there every time is starting to be tidius. There is any other way to do so? In blender you can press numpad numbers for example..
Thank you.
Comment
Best Answer
Answer by Hellium · May 01, 2021 at 12:14 PM
The Shortcut Manager does not have this shortcuts, but you can add your very own ones very easily.
Create a new file called SceneViewShortcuts.cs
and put it in an Editor folder under Assets. Copy-paste the following code in this file, and you will have several new shortcuts to do what you want:
using UnityEngine;
using UnityEditor;
using UnityEditor.ShortcutManagement;
public static class SceneViewShortcuts
{
[Shortcut("Scene View Camera - Top view", KeyCode.Keypad8)]
public static void TopView()
{
MakeSceneViewCameraLookAtPivot(Quaternion.Euler(90, 0, 0));
}
[Shortcut("Scene View Camera - Bottom view", KeyCode.Keypad2)]
public static void BottomView()
{
MakeSceneViewCameraLookAtPivot(Quaternion.Euler(-90, 0, 0));
}
[Shortcut("Scene View Camera - Right view", KeyCode.Keypad6)]
public static void RightView()
{
MakeSceneViewCameraLookAtPivot(Quaternion.Euler(0, -90, 0));
}
[Shortcut("Scene View Camera - Left view", KeyCode.Keypad4)]
public static void LeftView()
{
MakeSceneViewCameraLookAtPivot(Quaternion.Euler(0, 90, 0));
}
[Shortcut("Scene View Camera - Front view", KeyCode.Keypad7)]
public static void FrontView()
{
MakeSceneViewCameraLookAtPivot(Quaternion.Euler(0, 0, 0));
}
[Shortcut("Scene View Camera - Back view", KeyCode.Keypad1)]
public static void BackView()
{
MakeSceneViewCameraLookAtPivot(Quaternion.Euler(0, 180, 0));
}
[Shortcut("Scene View Camera - Toggle ortho/persp view", KeyCode.Keypad5)]
public static void ToggleOrthoPerspView()
{
SceneView sceneView = SceneView.lastActiveSceneView;
if (sceneView == null) return;
sceneView.orthographic = !sceneView.orthographic;
}
private static void MakeSceneViewCameraLookAtPivot(Quaternion direction)
{
SceneView sceneView = SceneView.lastActiveSceneView;
if (sceneView == null) return;
Camera camera = sceneView.camera;
Vector3 pivot = camera.transform.position + camera.transform.forward * sceneView.cameraDistance;
sceneView.LookAt(pivot, direction);
}
}
Wow, thank you. Wonder why unity doesn't introduce this option natively... mh!