Version 3.0.4.0

Odin has a dedicated attribute overview with examples

ShowIfAttribute 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 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.

Inheritance
  • System.Object
  • System.Attribute
  • ShowIfAttribute
Example

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;
}
Example

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;
	}
}

Constructors

ShowIfAttribute(String, Boolean)
Shows a property in the inspector, based on the value of a resolved string.
public ShowIfAttribute(string condition, bool animate = true)
Parameters
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.

ShowIfAttribute(String, Object, Boolean)
Shows a property in the inspector, if the resolved string evaluates to the specified value.
public ShowIfAttribute(string condition, object optionalValue, bool animate = true)
Parameters
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.

Fields

Animate
Whether or not to slide the property in and out when the state changes.
public bool Animate
Condition
A resolved string that defines the condition to check the value of, such as a member name or an expression.
public string Condition
Value
The optional condition value.
public object Value