Game Development Reference
In-Depth Information
// Return false if no transform is selected.
return Selection.activeTransform != null;
}
This simple validator just checks whether you have a game object selected in the editor; if
not, then MenuItem1 is disabled.
This new validation function is evaluated by the editor whenever it displays the menu
item of the same name. By setting the bool flag at the end of the MenuItem attribute, it
tells the editor that this function provides the validation logic for a MenuItem attribute of
the same name. Then, the editor will enable or disable that MenuItem attribute based on
the return of the validator function.
Adding shortcut keys to a MenuItem attribute
If you add % and a letter to the end of your MenuItem attribute, Unity will also enable a
shortcut key for that letter.
So, %g would enable a shortcut of Ctrl + G on Windows and cmd + G on a Mac.
For example, add a new function to our MyMenu script as follows:
[MenuItem ("MenuName/MenuItem2 %g")]
static void EnableMyOtherAwesomeFeature()
{
Debug.Log ("Find my key and win the prize - g");
}
This will show us an additional option with the shortcut defined, as you can see here:
Search WWH ::




Custom Search