Version 3.3.1.2

Odin has a dedicated attribute overview with examples

ToggleGroupAttribute 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 = true, Inherited = true)]
[Conditional("UNITY_EDITOR")]
public sealed class ToggleGroupAttribute : PropertyGroupAttribute, _Attribute

ToggleGroup is used on any field, and create a toggleable group of options.

Use this to create options that can be enabled or disabled.

Inheritance
Remarks

The ToggleMemberName functions as the ID for the ToggleGroup, and therefore all members of a toggle group must specify the same toggle member.

note

This attribute does not support static members!

Example

The following example shows how ToggleGroup is used to create two separate toggleable groups.

public class MyComponent : MonoBehaviour
{
	// This attribute has a title specified for the group. The title only needs to be applied to a single attribute for a group.
	[ToggleGroup("FirstToggle", order: -1, groupTitle: "First")]
	public bool FirstToggle;

	[ToggleGroup("FirstToggle")]
	public int MyInt;

	// This group specifies a member string as the title of the group. A property or a function can also be used.
	[ToggleGroup("SecondToggle", titleStringMemberName: "SecondGroupTitle")]
	public bool SecondToggle { get; set; }

	[ToggleGroup("SecondToggle")]
	public float MyFloat;

	[HideInInspector]
	public string SecondGroupTitle = "Second";
}
See Also

Constructors

ToggleGroupAttribute(String, Single, String)
Creates a ToggleGroup. See ToggleGroupAttribute.
public ToggleGroupAttribute(string toggleMemberName, float order = 0F, string groupTitle = null)
Parameters
System.String toggleMemberName

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

System.Single order

The order of the group.

System.String groupTitle

Use this to name the group differently than toggleMemberName.

ToggleGroupAttribute(String, String)
Creates a ToggleGroup. See ToggleGroupAttribute.
public ToggleGroupAttribute(string toggleMemberName, string groupTitle)
Parameters
System.String toggleMemberName

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

System.String groupTitle

Use this to name the group differently than toggleMemberName.

Fields

CollapseOthersOnExpand
If true, all other open toggle groups will collapse once another one opens.
public bool CollapseOthersOnExpand
ToggleGroupTitle
Title of the toggle group in the inspector. If null ToggleMemberName will be used instead.
public string ToggleGroupTitle

Properties

ToggleMemberName
Name of any bool field, property or function to enable or disable the ToggleGroup.
public string ToggleMemberName { get; }

Methods

CombineValuesWith(PropertyGroupAttribute)
Combines the ToggleGroup with another ToggleGroup.
protected override void CombineValuesWith(PropertyGroupAttribute other)
Parameters
PropertyGroupAttribute other

Another ToggleGroup.