Unity MenuItem API
public MenuItem(string itemName);
public MenuItem(string itemName, bool isValidateFunction);
public MenuItem(string itemName, bool isValidateFunction, int priority);
Unity MenuItemAttribute API
[MenuItem ("MyMenu/Do Something")]
static void DoSomething () {
Debug.Log ("Doing Something...");
}
[MenuItem ("MyMenu/Log Selected Transform Name")]
static void LogSelectedTransformName ()
{
Debug.Log ("Selected Transform is on " + Selection.activeTransform.gameObject.name + ".");
}
[MenuItem ("MyMenu/Log Selected Transform Name", true)]
static bool ValidateLogSelectedTransformName () {
return Selection.activeTransform != null;
}
[MenuItem ("MyMenu/Do Something with a Shortcut Key %g")]
static void DoSomethingWithAShortcutKey () {
Debug.Log ("Doing something with a Shortcut Key...");
}
[MenuItem ("CONTEXT/Rigidbody/Double Mass")]
static void DoubleMass (MenuCommand command) {
Rigidbody body = (Rigidbody)command.context;
body.mass = body.mass * 2;
Debug.Log ("Doubled Rigidbody's Mass to " + body.mass + " from Context Menu.");
}
[MenuItem("GameObject/MyCategory/Custom Game Object", false, 10)]
static void CreateCustomGameObject(MenuCommand menuCommand) {
GameObject go = new GameObject("Custom Game Object");
GameObjectUtility.SetParentAndAlign(go, menuCommand.context as GameObject);
Undo.RegisterCreatedObjectUndo(go, "Create " + go.name);
Selection.activeObject = go;
}
CreateAssetMenu API
[CreateAssetMenu(fileName="x",menuName="(custom) X")]
[System.Serializable]
public class X : ScriptableObject {
public float m_a;
}