Version 3.0.0.2

Odin has a dedicated attribute overview with examples

OnStateUpdateAttribute 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 OnStateUpdateAttribute : Attribute, _Attribute

OnStateUpdate provides an event callback when the property's state should be updated, or rather, when the IOnStateUpdate interface gets invoked. This generally happens at least once per frame, and the callback will be invoked even when the property is not visible. This can be used to approximate custom state controllers like [ShowIf] without needing to make entire attributes and drawers for one-off cases.

Inheritance
  • System.Object
  • System.Attribute
  • OnStateUpdateAttribute
Example

The following example shows how OnStateUpdate can be used to control the visible state of a property.

public class MyComponent : MonoBehaviour
{
	[OnStateUpdate("@$property.State.Visible = ToggleMyInt")]
	public int MyInt;

	public bool ToggleMyInt;
}
Example

The following example shows how OnStateUpdate can be used to control the expanded state of a list.

public class MyComponent : MonoBehaviour
{
	[OnStateUpdate("@$property.State.Expanded = ExpandList")]
	public List<string> list;

	public bool ExpandList;
}

The following example shows how OnStateUpdate can be used to control the state of another property.

public class MyComponent : MonoBehaviour
{
	public List>string< list;

	[OnStateUpdate("@#(list).State.Expanded = $value")]
	public bool ExpandList;
}

Constructors

OnStateUpdateAttribute(String)
public OnStateUpdateAttribute(string action)
Parameters
System.String action

Fields

Action
public string Action