Disable Menu Item

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.

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".

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.

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.

Last updated