• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by blitzen · Feb 15, 2012 at 09:17 PM · hotkeys

Scene Gizmo Hotkeys

To align your editor's scene window view to an axis, it is arduous to find the corresponding leg of the Scene Gizmo and click it with the mouse:

Are there keyboard shortcuts for the axes, akin to Numpad 1, 3, and 7 in Blender?

If not, how might one implement them with an editor script?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by FishBone · Feb 16, 2012 at 09:27 AM

Couldn't find any hotkeys myself, but it is possible to make a script to do it.

 using UnityEngine;
 using UnityEditor;
 using System.Collections;
 
 class GizmoTest {
     
     [MenuItem ("Gizmo/Front View _1")]
     static void FrontView () {
         GetSceneView().orthographic = true;
         GetSceneView().LookAtDirect(GetSceneView().pivot,
             Quaternion.LookRotation(Vector3.forward));
     }
     
     
     [MenuItem ("Gizmo/Side View _3")]
     static void SideView () {
         GetSceneView().orthographic = true;
         GetSceneView().LookAtDirect(GetSceneView().pivot,
             Quaternion.LookRotation(Vector3.right));
     }
     
     [MenuItem ("Gizmo/Top View _7")]
     static void TopView () {
         GetSceneView().orthographic = true;
         GetSceneView().LookAtDirect(GetSceneView().pivot,
             Quaternion.LookRotation(Vector3.down));
     }
     
     [MenuItem ("Gizmo/Perspective View _5")]
     static void PerspectiveView () {
         GetSceneView().orthographic = !GetSceneView().orthographic;
         GetSceneView().LookAtDirect(GetSceneView().pivot,
             Quaternion.LookRotation(Vector3.forward + Vector3.right + Vector3.down));
     }
     
     static SceneView GetSceneView() {
         SceneView activeSceneView = null;
         
         if (SceneView.lastActiveSceneView != null) {
             activeSceneView = SceneView.lastActiveSceneView;
         }
         else if (SceneView.sceneViews.Count != 0){
             activeSceneView = (SceneView.sceneViews[0] as SceneView);
         }
         
         return activeSceneView;
     }
 }


This script will work on all the numbers of the keyboard, don't know if there is any way to only check numpad.

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image blitzen · Feb 16, 2012 at 05:06 PM 0
Share

Saving it as "GizmoTest.cs" in the Editor folder, I'm getting this error for each of the four menu entries:

Assets/Editor/GizmoTest.cs(8,23): error CS1061: Type UnityEditor.SceneView' does not contain a definition for LookAtDirect' and no extension method LookAtDirect' of type UnityEditor.SceneView' could be found (are you missing a using directive or an assembly reference?)

Also I'm not seeing an entry for "SceneView" in the scripting reference. Where is that defined?

avatar image FishBone · Feb 16, 2012 at 08:16 PM 0
Share

Weird. $$anonymous$$aybe it's something new in 3.5? If you use an older version.

But if it's just a problem with LookAtDirect, change it to LookAt. That one looks cooler anyway :)

avatar image blitzen · Feb 16, 2012 at 11:08 PM 0
Share

Indeed I was still on 3.4.0f5. I didn't realize 3.5 was out of beta. Score.

After upgrading, it works now. Looks like they still haven't updated the docs yet though; SceneView and LookAtDirect() don't show up in the scripting reference. Where did you find out about them? And yes, LookAt() smoothly interpolates between views. :)

Good job. To mimic Blender more precisely, 3 would have you looking toward Vector3.left (not right), and 5 would toggle ortho and perspective like you have it but it's not necessary to also change the view there. Thus $$anonymous$$e is now:

 using UnityEngine;
 using UnityEditor;
 using System.Collections;
 class GizmoTest{
     [$$anonymous$$enuItem("Gizmo/Front View _1")]
     static void FrontView(){
        GetSceneView().orthographic=true;
        GetSceneView().LookAt(GetSceneView().pivot,Quaternion.LookRotation(Vector3.forward));
     }
     [$$anonymous$$enuItem("Gizmo/Side View _3")]
     static void SideView(){
        GetSceneView().orthographic=true;
        GetSceneView().LookAt(GetSceneView().pivot,Quaternion.LookRotation(Vector3.left));
     }
     [$$anonymous$$enuItem("Gizmo/Top View _7")]
     static void TopView(){
        GetSceneView().orthographic=true;
        GetSceneView().LookAt(GetSceneView().pivot,Quaternion.LookRotation(Vector3.down));
     }
     [$$anonymous$$enuItem("Gizmo/Perspective View _5")]
     static void PerspectiveView(){
        GetSceneView().orthographic=!GetSceneView().orthographic;
     }
     static SceneView GetSceneView(){
        SceneView activeSceneView=null;
        if(SceneView.lastActiveSceneView!=null)activeSceneView=SceneView.lastActiveSceneView;
        else if(SceneView.sceneViews.Count!=0)activeSceneView=(SceneView.sceneViews[0] as SceneView);
        return activeSceneView;
     }
 }

I'll let you know if I find a way to specify numpad keys as shortcuts, unless someone else chimes in.

avatar image blitzen · Feb 17, 2012 at 12:08 AM 0
Share

Crap, I just realized it eats your 1, 3, 5 and 7 keys even when you're trying to type values into Inspector fields. We'll have to bind them to something else until we figure out how to differentiate between numpad keys and keyboard numbers for shortcuts.

Edit: I discovered you can code it as "_Numpad 1" but that has the exact same effect as just "_1". Weird.

avatar image FishBone · Feb 17, 2012 at 09:21 AM 0
Share

I didn't think about that :) As i always use the numpad for entering values changing to only affect numpad won't cut it for me, so i did a check for if the sceneview is the active window ins$$anonymous$$d.

Just add this in the GetSceneView-function

if (EditorWindow.focusedWindow != activeSceneView) activeSceneView = null;

and do a check for if GetSceneView==null in the View-functions by adding

if (GetSceneView() == null) return;

in the first line.

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Hotkey for play (ctrl + P) not working properly 0 Answers

Global/local axis hotkey 2 Answers

Custom hot keys manager 1 Answer

_a / _b /_c ...etc.. is supposed to set a hotkey as "a,b,c" but doesn't? 0 Answers

Overriding "Ctrl +" in Custom Editor 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges