Firstborn/Library/PackageCache/com.unity.terrain-tools@4.0.5/Documentation~/create-shortcut-handlers.md
Schaken-Mods 4ff395c862 Finished the NPC Creator tool
Finished the NPC Creator tool
2023-04-27 18:37:28 -05:00

1.4 KiB

Shortcut handlers

You can use the ShortcutManagement API to add shortcuts to your custom Terrain tools. Shortcut handlers let you use hotkeys to select specific tools or quickly modify tool settings without the need for you to interact with the tool's UI.

using UnityEngine;
using UnityEditor.ShortcutManagement;
using UnityEditor.TerrainTools;

public class CustomTerrainToolWithShortcut : TerrainPaintTool<CustomTerrainToolWithShortcut>
{
    // Add the Shortcut attribute and provide the name of the shortcut and context Type
    [Shortcut("Terrain/Select CustomTerrainToolWithShortcut", typeof(UnityEditor.TerrainTools.TerrainToolShortcutContext))]
    static void SelectShortcut(ShortcutArguments args)
    {
        // Get the TerrainTool-specifc context from the ShortcutArguments
        UnityEditor.TerrainTools.TerrainToolShortcutContext context = (UnityEditor.TerrainTools.TerrainToolShortcutContext)args.context;
        // Select this tool
        context.SelectPaintTool<CustomTerrainToolWithShortcut>();
    }

    public override string GetName()
    {
        return "Custom Terrain Tool With Shortcut";
    }

    public override string GetDescription()
    {
        return "My custom Terrain Tool is amazing!";
    }

    public override void OnRenderBrushPreview(Terrain terrain, IOnSceneGUI editContext)
    {

    }

    public override bool OnPaint(Terrain terrain, IOnPaint editContext)
    {
        return true;
    }
}