Version 2.1.0.0

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)]
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, Int32, String)
Creates a ToggleGroup. See ToggleGroupAttribute.
public ToggleGroupAttribute(string toggleMemberName, int order = 0, string groupTitle = null)
Parameters
System.String toggleMemberName

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

System.Int32 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.

This website is brand new and built with the Odin 2.1 beta in mind. This means you might discover some features such as attribute expressions that are only available in the beta.

You can download the 2.1 beta from here and read the patch-notes here.