Search Unity

Question Shortcut GameView

Discussion in 'Editor & General Support' started by mitaywalle, Oct 23, 2021.

  1. mitaywalle

    mitaywalle

    Joined:
    Jul 1, 2013
    Posts:
    253
    Hello! I wanna make editor-only hotkey using Shortcuts, to Toggle 'Slow motion' using Time.timeScale.
    Code is simple, but it work in any other window, except GameView.
    Code (CSharp):
    1. using UnityEditor.ShortcutManagement;
    2. using UnityEngine;
    3. namespace Plugins.mitaywalle.Editor
    4. {
    5.     public class SlowMoShortcuts
    6.     {
    7.         [Shortcut("Debug/Toggle SlowMo", KeyCode.F6)]
    8.         public static void ToggleSlowMo()
    9.         {
    10.             Debug.Log("Toggle slow mo");
    11.  
    12.             if (Time.timeScale == 1)
    13.             {
    14.                 Time.timeScale = .25f;
    15.             }
    16.             else
    17.             {
    18.                 Time.timeScale = 1;
    19.             }
    20.         }
    21.     }
    22. }
    - I understand, that there may be conflicts with UnityEngine.Input and Unity.InputSystem, project use both.
    My Custom Shortcut for 'Main Menu/Edit/Pause'/'Unpause' work in GameView.

    I don't want to use MonoBehavior.Update() or EditorApplication.update for this. Is this possible using Shortcut system only?

    If not, this a bit of waste
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    I'm not sure you can get there from here... a lot of stuff gets "eaten" by the play screen when the game is running, stuff that otherwise works in the Game window when not running. For instance zoom in/out with mouse wheel in Game works when the editor is not running, but fails when running.

    If you have any class in your game that ALWAYS starts up, I would put an editor-only singleton-creator that starts up an instance of the above. Make the above a MonoBehaviour that has Update() and watches for your key... that way when Game doesn't have focus the key binding should work, but when Game has focus the Update() will catch it. Might not be 100% seamless but oughta be pretty slick.
     
    mitaywalle likes this.
  3. mitaywalle

    mitaywalle

    Joined:
    Jul 1, 2013
    Posts:
    253
    Hello, thanks for answer, but as i sad, I don't want to use MonoBehavior.Update() or EditorApplication.update for this.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    How unusual.

    Good luck!