Version 3.3.1.2

Odin has a dedicated attribute overview with examples

ToggleAttribute class

Namespace: Sirenix.OdinInspector
Assembly: Sirenix.OdinInspector.Attributes
[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 = false, Inherited = true)]
[Conditional("UNITY_EDITOR")]
public sealed class ToggleAttribute : Attribute, _Attribute

Toggle is used on any field or property, and allows to enable or disable the property in the inspector.

Use this to create a property that can be turned off or on.

Inheritance
  • System.Object
  • System.Attribute
  • ToggleAttribute
Remarks

note

Toggle does current not support any static members for toggling.

Example

The following example shows how Toggle is used to create a toggleable property.

public class MyComponent : MonoBehaviour
{
	[Toggle("Enabled")]
	public MyToggleable MyToggler = new MyToggleable();
}

public class MyToggleable
{
	public bool Enabled;

	public int MyValue;
}

Constructors

ToggleAttribute(String)
Create a togglable property in the inspector.
public ToggleAttribute(string toggleMemberName)
Parameters
System.String toggleMemberName

Name of any bool field or property to enable or disable the object.

Fields

CollapseOthersOnExpand
If true, all other open toggle groups will collapse once another one opens.
public bool CollapseOthersOnExpand
ToggleMemberName
Name of any bool field or property to enable or disable the object.
public string ToggleMemberName