Firstborn/Library/PackageCache/com.unity.terrain-tools@4.0.5/Documentation~/create-shortcut-handlers.md

44 lines
1.4 KiB
Markdown
Raw Normal View History

2023-03-28 13:24:16 -04:00
# 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>
2023-03-28 13:24:16 -04:00
{
// 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()
2023-03-28 13:24:16 -04:00
{
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;
}
}
2023-03-28 13:24:16 -04:00
```