Rasagar/Library/PackageCache/com.unity.terrain-tools/Documentation~/create-shortcut-handlers.md
2024-08-26 23:07:20 +03:00

1.5 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 : TerrainPaintToolWithOverlays<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.SelectPaintToolWithOverlays<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;
    }
}