unity3d Menu attributes


Example

[AddComponentMenu( "Examples/Attribute Example" )]
public class AttributesExample : MonoBehaviour 
{
    [ContextMenuItem( "My Field Action", "MyFieldContextAction" )]
    public string MyString;

    private void MyFieldContextAction() 
    {
        [...]
    }

    [ContextMenu( "My Action" )]
    private void MyContextMenuAction() 
    {
        [...]
    }
}

The result of the [AddComponentMenu] attribute

Result 1

The result of the [ContextMenuItem] attribute

Result 2

The result of the [ContextMenu] attribute

Result 3


[AddComponentMenu( "Examples/Attribute Example" )]
public class AttributesExample : MonoBehaviour 

The AddComponentMenu attribute allows you to place your component anywhere in the Component menu instead of the Component->Scripts menu.

[ContextMenuItem( "My Field Action", "MyFieldContextAction" )]
public string MyString;

private void MyFieldContextAction() 
{
    [...]
}

The ContextMenuItem attribute allows you to define functions that can be added to the context menu of a field. These functions will be executed upon selection.

[ContextMenu( "My Action" )]
private void MyContextMenuAction() 
{
    [...]
}

The ContextMenu attribute allows you to define functions that can be added to the context menu of the component.