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")]
[IncludeMyAttributes]
[HideInTables]
public sealed class OnStateUpdateAttribute : Attribute, _Attribute
OnStateUpdate provides an event callback when the property's state should be updated, when the StateUpdaters run on the property instance. 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 StateUpdaters like [ShowIf] without needing to make entire attributes and StateUpdaters for one-off cases.
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;
}
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;
}
public OnStateUpdateAttribute(string action)
System.String | action |
public string Action