‎ ‎
On the Asset Store
Hats
Hats
  • Intro
  • Changelog
  • Workspaces
    • Workspaces
    • Switching workspaces
    • Workspace rules
      • Select Folder
      • Highlight Gizmos
      • Open Scenes
      • Scene Camera to Position
      • Load Layout
      • Lock/Hide Objects
      • Disable Menu Item
      • Lock Folders
  • Teams
    • Teams
    • Switching Teams
  • Building on Hats
    • Building Hats-based tools
Powered by GitBook
On this page
  • On workspace enabled
  • On workspace disabled
  • Setup
  1. Workspaces
  2. Workspace rules

Disable Menu Item

Last updated 5 months ago

Use this rule to render some menu items inaccessible.

On workspace enabled

The specified menu item gets disabled, and won't be clickable.

On workspace disabled

The disabled menu item is enabled again.

Not all menu items can be disabled. For instance, you can't disable the ones under File or Edit.

Setup

This rule is a bit special, in that it doesn't have Inspector properties you can set. This is because the trick used to disable a menu item requires the item to be compiled in code, so it can't be an Inspector property. You will notice that the default one, provided as an example, only ever disables "Window/PackageManager".

The code you need to change is clearly highlighted:

// -- Start of customisable block
private const string MenuPath = "Window/Package Manager";
        
[MenuItem(MenuPath, true)]
private static bool ValidateMenuItem() => !_itemIsActive;

// -- End of customisable block

Just change the value of the MenuPath variable to the item you want to disable.

You can also duplicate that whole block and disable multiple menu items in one go (you need to rename the method to avoid name clashes).

Alternatively, duplicate the script again and repeat the process.

To use this rule, duplicate the DisableMenuItem.cs script contained in Packages/Hats/Editor/Rules/, and modify the code inside to include any menu item you need to disable.

📂