Game Development Reference
In-Depth Information
From here, you can execute whatever you need to.
Tip
When you return to Unity after adding a menu script, it may sometimes not show up im-
mediately. You can either click on the menu bar or restart the editor to make it appear (it
just needs a nudge).
Enabling/disabling a MenuItem attribute
We can extend this further by adding a validation logic method to support a MenuItem
attribute. This controls whether the menu option is enabled or not.
For this, you need to create a pair of the following items:
• A menu item
• A menu item validator
Note
The menu item and the menu item validator must have the same menu path. So, if the
menu item (as declared previously) is [MenuItem ("MenuName/MenuItem1")] ,
the validator must have the same menu definition as follows:
[MenuItem ("MenuName/MenuItem1", true)]
Validators do not add menu items. They only extend or validate the existing menu items.
So, using the menu item we just added earlier, we can add a validator menu function. It
must have a return type of bool and an additional flag set against the function attribute,
as follows:
[MenuItem ("MenuName/MenuItem1", true)]
static bool CheckifaGameObjectisselected() {
Search WWH ::




Custom Search