|
The MenuItem attribute allows you to add menu items to the main menu and inspector context menus.
Note: This is an editor class. To use it you have to place your script in Assets/Editor inside your project folder. Editor classes are in the UnityEditor namespace so for C# scripts you need to add "using UnityEditor;" at the beginning of the script.
The MenuItem attribute turns any static function into a menu command. Only static functions can use the MenuItem attribute.
To create a hotkey you can use the following special characters: % (ctrl on Windows, cmd on OS X), # (shift), & (alt), _ (no key modifiers). For example to create a menu with hotkey shift-alt-g use "GameObject/Do Something #&g". To create a menu with hotkey g and no key modifiers pressed use "GameObject/Do Something _g". A hotkey text must be preceded with a space character ("GameObject/Do_g" won't be interpreted as hotkey, while "GameObject/Do _g" will).
MenuItem |
Creates a menu item and invokes the static function following it, when the menu item is selected. |