The Unity editor is very powerful and allows a huge extensibility. In this post, I will focus on how create a custom Menu Item.

The MenuItem attribute allows you to add menu items to the main menu and inspector context menus.

Simple Menu Item

using UnityEditor;
using UnityEngine;

public class MyCustomMenu : MonoBehaviour
{
	[MenuItem("MyMenu/Hello world")]
	private static void SayHello()
	{
		Debug.Log("Hello world!");
	}
}

MenuItem(string itemName);

Menu Item with shortcut

using UnityEditor;
using UnityEngine;

public class MyCustomMenu : MonoBehaviour
{
	[MenuItem("MyMenu/Hello world %h")]
	private static void SayHelloWithShortcut()
	{
		Debug.Log("Hello world!");
	}
}

MenuItem(string itemName);

The shortcut is set by adding %h. For more information see http://docs.unity3d.com/ScriptReference/MenuItem.html

Menu Item with validation

using UnityEditor;
using UnityEngine;

public class MyCustomMenu : MonoBehaviour
{
	[MenuItem("MyMenu/Hello world")]
	private static void SayHello()
	{
		Debug.Log("Hello world!");
	}

	[MenuItem("MyMenu/Hello world", true)]
	private static bool CanSayHello()
	{
		return Selection.activeGameObject != null;
	}
}

MenuItem(string itemName, bool isValidateFunction);

The second parameter of the MenuItem constructor allow you to add a validation method who will be launched before the main method.

Menu Item with priority

using UnityEditor;
using UnityEngine;

public class MyCustomMenu : MonoBehaviour
{
	[MenuItem("MyMenu/Hello world", false, 1)]
	private static void SayHello()
	{
		Debug.Log("Hello world!");
	}

	[MenuItem("MyMenu/ByeBye", false, 3)]
	private static void SayBye()
	{
		Debug.Log("Bye bye!");
	}
}

 MenuItem(string itemName, bool isValidateFunction, int priority);

The third parameter of the MenuItem constructor allow you to add a priority level to be able to order items in the menu.