Search Unity

IShortcutToolContext -- Can I use it, pretty please??

Discussion in 'UIElements' started by awesomedata, Jul 28, 2019.

  1. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    834
    As explained, I really want to use IShortcutToolContext in my shortcuts (for continuous interactive scene control via my own (user-reassignable) shortcuts.)

    This interface is used in the flythrough mode in the scene camera controller. I want to use it in other tools.


    In 2019.1, it's currently not possible to add any truly interactive scene controls (using the new ShortcutManagement system) without this -- all because this interface was deemed "internal" only for some reason.

    There are SO MANY great tools that can be made by users like me with access to this interface (such as completely custom scene camera controllers!) -- And it would bring money to Unity on the Asset Store too, so it's win-win.
    So why am I not allowed to implement my own camera orbit behavior -- or even my own gradual color tweak tool for modifying a gameobject's color while holding a key for R, G, or B?
    These are simple tool ideas, but much better stuff could be made if people had access to this when designing their games!!

    Lots of cool tools will never be possible with the new shortcut management system policing our access to things like this. So please open this context up (and add more!) so you can democratize this type of stuff too, @Unity!
     
  2. leo-carneiro

    leo-carneiro

    Unity Technologies

    Joined:
    Sep 1, 2011
    Posts:
    49
    Hi,

    Glad to hear that you are looking into using the new Shortcut Manager APIs.

    We were expecting that with the APIs we have exposed so far, it would indeed be possible to build interactive scene controls by using the SceneView as the ShortcutContext.

    Can you expand a bit more on what exactly are you trying to achieve that you are not able to do with current public API?

    Cheers!
     
    Lars-Steenhoff likes this.
  3. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    834
    I, for example, have an asset that lets me drive the scene camera however I wish in older Unity versions. I had to do some hacks to get this working, but it worked pretty decently. I had my own orbit and zoom that worked way better than Unity's default scene camera controller. However, moving the scene camera in real-time using the new shortcut management system in 2019.x is impossible due to having to jump through hoops to define a proper tool when I simply want a key to respond and execute a script until I tell it to stop by letting go of the key.

    In tool examples like the RGB shifting in real-time, I don't necessarily want this to be tied to an editor window. In the case of a scene camera, I don't necessarily want this to be tied to a particular editor window. For example, maybe I want to hold control and switch to an entirely different method of navigating my scene -- i.e. I might only want my orthographic scene camera to shift by exactly 1 screen at a time with a slight delay as long as I am holding the control key and holding my arrow keys.

    That same example could apply to moving the selected gameobject along a grid, with a scene raycast to determine the height of the next grid cell before shifting it, with this method being repeated as long as an arrow key is being pressed in the editor. This is nothing but a quality of life improvement tool for navigating a scene for a particular game style, but it can make life amazing for the person using it for a grid-based game.

    By no means is this limited to scene camera/gameobject tools though. The ability to play a physics simulation while holding a key and stopping at just the right moment upon releasing it could be another good use of realtime editor shortcuts. Doing this with a button or a dedicated tool simply wouldn't allow the sort of fine control one might need for lots of iterations through groups of gameobjects when decorating a scene with lots of physically placed objects via simulations. There are just some occasions in the editor when you simply need a constant keyboard press to execute a static method until the editor realizes you've stopped pressing it.

    Thus far, I've only mentioned the scene view, but there are also times when I want to essentially program the equivalent of a macro too. For example, I might want to press and hold a single key to temporarily display an editor window (i.e the Game View) and then hide it when I release the key. I actually do this with Snapcam's windows, which proved to be problematic when trying to use a pop-up window that should have also been dockable (the Grid Navigator), but broke Unity when trying to do that particular thing. The problem was, some customers of mine liked it as a quick popup, but others liked it docked. Some wanted to be able to do both with the same physical window. I had to do some fancy reflection magic just to hide and show my suite of windows via shortcuts that could be accessed globally in previous versions of Unity, so I was excited to see a proper shortcut system in the works. However, I can't be tied down to the scene view as my context because all of my tools -- and their editor windows -- were designed to get the heck out of your way when you no longer needed them. This means an invisible editor window that handles logic like shortcuts. This design is impossible using the scene view context alone, since some of my tools I've planned have nothing to do with the scene view and act as their own sort of management systems that work across multiple window contexts. What if the user closes the scene view window? Ultimately, it's too hacky to do things as I did pre-2019. I can currently not make these according to my design without the system being unwieldy again.

    IShortcutToolContext seems like it would be a great fit for game-specific quality of life tools as much as it would be a great fit for tools that modify the editor UI itself, such as me wanting to override the sleek new editor camera controller to make a version that orbits and moves exactly how _I_ want it to for editing _my_ specific game.

    To put such essential UX stuff out of the hands of advanced users capable of understanding and controlling it should be a crime in my personal opinion. Unity has been too unwieldy for much too long for this to still be okay with you guys. :(

    Please at least let us use or at least override stuff like the above-mentioned user-experience elements (such as this interface or the scene camera controller.) This would be so much appreciated by so many people.
     
  4. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    834
    So how might one use the SceneView as the ShortcutContext? -- As far as I'm aware, there's no way to use it as the context.


    Also, when I use something like:

    Code (CSharp):
    1. [Shortcut("MoveMode", null, KeyCode.A)]
    2.     static void MoveView ()
    3.     {
    4. //etc.
    5. }
    This executes only at the repeat rate of the keyboard.

    This is a problem. It doesn't repeat instantly (like using WASD in Flymode while holding RMB). I need the fluidity like that in my shortcut. In addition to this, overriding Mouse button behaviors in the scene context would be incredibly useful when you want to perform a different function than what the SceneView's SimpleCameraController enables. The "KeyCode.Mouse1" and others don't seem to work (and throw errors) in 2019.2 with using a null context. This might have something to do with the null context itself though, so being able to use mouse shortcuts in the scene view would be nice.


    Much of this I want to use to develop innovative tools and interfaces for UX purposes, but I can't do this without _at least_ this level of control.

    Being able to modify the current SceneView camera controller by overriding parts of it would be a first step (maybe make it a package??), but it wouldn't be general enough for some editor tools I want to make...
     
  5. teck_unity

    teck_unity

    Unity Technologies

    Joined:
    Jan 2, 2019
    Posts:
    3
    Code (CSharp):
    1.         [ClutchShortcut("MyShortcut", typeof(SceneView), KeyCode.C)]
    2.         static void MyShortcutMethod(ShortcutArguments args)
    3.         {
    4.             // can check args.stage here;
    5.             // ShortcutStage.Begin, ShortcutStage.End
    6.             // https://docs.unity3d.com/ScriptReference/ShortcutManagement.ShortcutStage.html
    7.         }
    The ClutchShortcut attribute allows you to get your keydown and keyup.
    (https://docs.unity3d.com/ScriptReference/ShortcutManagement.ClutchShortcutAttribute.html)
     
  6. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    834
    Thanks -- I've read the docs.

    What I _really_ want to know is how to overcome the keyboard repeat rate of something like KeyCode.C or KeyCode.A so I can use those shortcuts repeatedly in the SceneView context.

    How would I accomplish this?


    Also, I admit it never occurred to me to use typeof(SceneView) for the context though (I tried using "SceneView" directly -- maybe this should be mentioned in the docs?), so thanks for that at least.

    Sadly, it doesn't solve my problem.
     
  7. teck_unity

    teck_unity

    Unity Technologies

    Joined:
    Jan 2, 2019
    Posts:
    3
    Apologies, just saw this. At least for your use case, you'd simply need to set a boolean (true on down, false on up), and do the actual handling in the OnToolGUI method.

    In one of my own tools, I'm doing something similar to:
    Code (CSharp):
    1.         [ClutchShortcut("PivotTool/Adjust Pivot", typeof(SceneView), KeyCode.A)]
    2.         static void AdjustPivot(ShortcutArguments args)
    3.         {
    4.             // instance is a private static reference to the current tool which I assign in OnActiveToolChange
    5.             if (!EditorTools.IsActiveTool(instance))
    6.             {
    7.                 return;
    8.             }
    9.             instance.adjustPivot = args.stage == ShortcutStage.Begin;
    10.         }
    11.  
    12.         public override void OnToolGUI(EditorWindow window)
    13.         {
    14.                         if (adjustPivot)
    15.                         {
    16.                                 // do adjust pivot stuff
    17.                         }
    18.                         else
    19.                         {
    20.                                 // do other stuff
    21.                         }
    22.         }
     
  8. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    834
    Thanks for getting back to me -- I know you are busy.


    Err... um.... Thanks, but this was exactly what I'd hoped I'd not have to do...

    There are times when the "ClutchShortcut" doesn't "Clutch" the key release -- This occurs especially when swapping focus with another area or interface (i.e. like when opening/using interdependent windows/tools like Navigation Studio does) -- which then causes the bool to miss getting set back to false, when the context changes to some other window, which thus prevents further (proper) use of the tool.

    Why not just offer an attribute or something that would let the shortcut work this way _without_ jumping through hoops like these? -- This method seems really clunky and error-prone, and is probably hard to understand for most people anyway...


    I know I'm not the only one who needs to make my own interactive toolsets...