Version 2.1.0.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)]
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 methodName)
Parameters
System.String menuItem

The name of the menu item.

System.String methodName

The name of the callback method.

Fields

MenuItem
The name of the menu item.
public string MenuItem
MethodName
The name of the callback method.
public string MethodName