Skip to main content

Class ShowIfAttribute

Attribute that conditionally shows a field in the Unity Inspector based on one or more boolean condition fields.

public class ShowIfAttribute : EnableIfAttribute

Inheritance​

Derived​

HideIfAttribute

Inherited Members​

Examples​

Show a field only when the "IsVisible" bool is true:

public bool IsVisible;
[ShowIf(nameof(IsVisible))]
public int SomeValue;

Remarks​

Inherits from EnableIfAttribute, but instead of disabling the property, it hides it completely when the condition is not met.

Constructors​

ShowIfAttribute(string, int)​

Creates a new instance of ShowIfAttribute with a single condition.

public ShowIfAttribute(string conditionName, int order = 0)

Parameters​

NameTypeDescription
conditionNamestringThe name of the boolean property that controls visibility.
orderintThe drawer order for rendering (optional).

ShowIfAttribute(EConditionOperator, int, params string[])​

Creates a new instance of ShowIfAttribute with multiple conditions.

public ShowIfAttribute(EConditionOperator operatorType, int order = 0, params string[] conditionNames)

Parameters​

NameTypeDescription
operatorTypeEConditionOperatorLogical operator used to evaluate multiple conditions.
orderintThe drawer order for rendering (optional).
conditionNamesstring[]An array of condition property names.