Search Unity

New Terrain Tools: Brush Size and Opacity hotkeys?

Discussion in 'World Building' started by Arycama, Mar 26, 2019.

  1. Arycama

    Arycama

    Joined:
    May 25, 2014
    Posts:
    184
    Are there still no hotkeys for changing brush size or opacity? If not, is there any way to add custom hotkeys for it? I've looked through all the new APIs but can't seem to find a way to change the brush size from script.

    This is probably the most frequent action performed when editing terrain, apart from clicking. I can't really understand how the terrain tools have been missing this functionality for so long.
     
    bernice_wang and dadude123 like this.
  2. wyattt_

    wyattt_

    Unity Technologies

    Joined:
    May 9, 2018
    Posts:
    424
    I don't think anyone was working on them until recently haha. 2018.3 was mostly performance updates for Terrain. We are now working on workflow improvements which include hotkeys and SceneView controls (ala Photoshop resizer with alt + mouse move) for brush settings.

    If you want to add hotkeys/controls for brush settings in your own tool, don't use the brush settings provided by any of the Context objects we give you via OnInspectorGUI, OnPaint, and OnSceneGUI. You can just use your own and then add ClutchShortcutAttribute (from the ShortcutManager API) to a function that you want to be called when modifying a specific brush setting like so:
    Code (CSharp):
    1.  
    2. [ClutchShortcut("Terrain/Adjust Brush Strength (SceneView)", typeof(TerrainToolShortcutContext), KeyCode.A)]
    3. static void StrengthBrushShortcut(ShortcutArguments args)
    4. {
    5.     // modify brush strength here or set the state for modifying brush strength
    6. }
     
    hippocoder and Rowlan like this.
  3. wyattt_

    wyattt_

    Unity Technologies

    Joined:
    May 9, 2018
    Posts:
    424
  4. wyattt_

    wyattt_

    Unity Technologies

    Joined:
    May 9, 2018
    Posts:
    424
    Forgot to mention that this is 2019.1+
     
  5. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Looks like a handy bit of wacom action coming down the pipes for people incapable of holding a mouse properly (yes, artists, I mean you).
     
  6. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    1,419
    So I'm using the following to perform a willy-nilly keypress in the editor to throw out a Debug.Log so I can test shortcuts, but I am finding I can't use the IShortcutToolContext due to its protection level.

    Is there anything I can do to execute a keypress globally and have it simply execute a function?

    This is what I have:

    Code (CSharp):
    1. using System.Collections;
    2. using UnityEditor.ShortcutManagement;
    3. using UnityEditor;
    4. using UnityEditorInternal;
    5.  
    6.  
    7. class ShortcutKeys : IShortcutToolContext
    8. {
    9.  
    10.     [ClutchShortcut("3D Viewport/Test" , typeof(ShortcutKeys) , KeyCode.A)]
    11.     public static void Stuff (ShortcutArguments args) {
    12.         Debug.Log("Yo");
    13.     }
    There is next to zero documentation on how to actually use this API to execute a function via shortcut without being bound to a particular EditorWindow.

    This error is what I'm getting:
    Code (CSharp):
    1. Ignoring shortcut attribute with invalid context type ShortcutKeys on ShortcutKeys.Stuff
    2. The context type must either be null, derive from UnityEditor.EditorWindow, or implement UnityEditor.ShortcutManagement.IShortcutToolContext.
    3. UnityEditor.EditorAssemblies:processInitializeOnLoadAttributes(Type[])
     
    Last edited: Jul 26, 2019
    Rowlan likes this.