Version 2.1.0.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)]
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, if the specified member returns true.
public ShowIfAttribute(string memberName, bool animate = true)
Parameters
System.String memberName

Name of a bool field, property or function to show or hide the property.

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 specified member returns the specified value.
public ShowIfAttribute(string memberName, object optionalValue, bool animate = true)
Parameters
System.String memberName

Name of a bool field, property or method to test the value of.

System.Object optionalValue

The value the member should equal for the property to shown.

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
MemberName
Name of a bool field, property or function to show or hide the property.
public string MemberName
Value
The optional member value.
public object Value