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 ShowIfAttribute : Attribute, _Attribute
ShowIf is used on any property and can hide the property in the inspector.
Use this to hide irrelevant properties based on the current state of the object.
This example shows a component with fields hidden by the state of another field.
public class MyComponent : MonoBehaviour
{
public bool ShowProperties;
[ShowIf("showProperties")]
public int MyInt;
[ShowIf("showProperties", false)]
public string MyString;
public SomeEnum SomeEnumField;
[ShowIf("SomeEnumField", SomeEnum.SomeEnumMember)]
public string SomeString;
}
This example shows a component with a field that is hidden when the game object is inactive.
public class MyComponent : MonoBehaviour
{
[ShowIf("MyVisibleFunction")]
public int MyHideableField;
private bool MyVisibleFunction()
{
return this.gameObject.activeInHierarchy;
}
}
public ShowIfAttribute(string condition, bool animate = true)
System.String | condition | A resolved string that defines the condition to check the value of, such as a member name or an expression. |
System.Boolean | animate | Whether or not to slide the property in and out when the state changes. |
public ShowIfAttribute(string condition, object optionalValue, bool animate = true)
System.String | condition | A resolved string that defines the condition to check the value of, such as a member name or an expression. |
System.Object | optionalValue | Value to check against. |
System.Boolean | animate | Whether or not to slide the property in and out when the state changes. |
public bool Animate
public string Condition
public object Value