Version 3.0.1.0

Odin has a dedicated attribute overview with examples

CustomContextMenuAttribute class

Namespace: Sirenix.OdinInspector
Assembly: Sirenix.OdinInspector.Attributes
[DontApplyToListElements]
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Parameter | AttributeTargets.Delegate | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter | AttributeTargets.All, AllowMultiple = true, Inherited = true)]
[Conditional("UNITY_EDITOR")]
public sealed class CustomContextMenuAttribute : Attribute, _Attribute

CustomContextMenu is used on any property, and adds a custom options to the context menu for the property.

Use this for when you want to add custom actions to the context menu of a property.

Inheritance
  • System.Object
  • System.Attribute
  • CustomContextMenuAttribute
Remarks

note

CustomContextMenu currently does not support static functions.

Example

The following example shows how CustomContextMenu is used to add a custom option to a property.

public class MyComponent : MonoBehaviour
{
	[CustomContextMenu("My custom option", "MyAction")]
	public Vector3 MyVector;

	private void MyAction()
	{
		MyVector = Random.onUnitSphere;
	}
}

Constructors

CustomContextMenuAttribute(String, String)
Adds a custom option to the context menu of the property.
public CustomContextMenuAttribute(string menuItem, string action)
Parameters
System.String menuItem

The name of the menu item.

System.String action

A resolved string defining the action to take when the context menu is clicked.

Fields

Action
A resolved string defining the action to take when the context menu is clicked.
public string Action
MenuItem
The name of the menu item.
public string MenuItem