SceneView (Editor) Local/World keyboard shortcut

Hey friends,

There is a shortcut ‘Z’, which allows to scale from pivot/center of object.
However, there is no key to change between local/global move/rotate/scale mode.

…Well, here is a script which allows to do just that :slight_smile:
Place it into an “Assets/Editor/” folder, naming the script as “GlobalLocalSpace_ShortcutTool”

using UnityEngine;
using UnityEditor;


//allows to switch between global-local space, in editor with the 'Tab' key.
//Place in the "Assets/Editor" folder.
// Igor Aherne, 14th August 2017  www.facebook.com/igor.aherne
[InitializeOnLoad]
public static class GlobalLocalSpace_ShortcutTool {

    static bool currPressingSpace = false;
    static bool currDraggingLeftMouse = false;
    static bool currDraggingRightMouse = false;

    static Event _currEvent;



    static GlobalLocalSpace_ShortcutTool() {
        SceneView.onSceneGUIDelegate -= OnSceneView;
        SceneView.onSceneGUIDelegate += OnSceneView;
    }


    static void OnSceneView(SceneView sv) {
        _currEvent = Event.current;


        if (_currEvent.isKey == false) {
            return;
        }

        if (_currEvent.keyCode != KeyCode.Tab) {
            return;
        }

        if (_currEvent.type != EventType.KeyDown) {
            return;
        }

        //cycle between world & local spaces:.
        var differentMode = Tools.pivotRotation == PivotRotation.Global ? PivotRotation.Local : PivotRotation.Global;
        Tools.pivotRotation = differentMode;
    }

}

Thanks, this is very useful.
I modified the script so that Unity 2020.2 doesn’t complain about deprecation:

using UnityEngine;
using UnityEditor;

//allows to switch between global-local space, in editor with the 'Tab' key.
//Place in the "Assets/Editor" folder.
// Igor Aherne, 14th August 2017  www.facebook.com/igor.aherne
[InitializeOnLoad]
public static class GlobalLocalSpace_ShortcutTool {

    static Event _currEvent;

    static GlobalLocalSpace_ShortcutTool()
    {
        SceneView.duringSceneGui -= OnSceneView;
        SceneView.duringSceneGui += OnSceneView;
    }

    static void OnSceneView(SceneView sv) {
        _currEvent = Event.current;

        if (_currEvent.isKey == false) {
            return;
        }

        if (_currEvent.keyCode != KeyCode.Tab) {
            return;
        }

        if (_currEvent.type != EventType.KeyDown) {
            return;
        }

        //cycle between world & local spaces:.
        var differentMode = Tools.pivotRotation == PivotRotation.Global ? PivotRotation.Local : PivotRotation.Global;
        Tools.pivotRotation = differentMode;
    }
}
1 Like

In 2021.3 I’m using ‘X’ shortcut built-in in Unity itself

1 Like