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
Inherited Members
- EnableIfAttribute.ConditionNames
- EnableIfAttribute.Operator
- EnableIfAttribute.GetCondition(SerializedProperty)
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
| Name | Type | Description |
|---|---|---|
conditionName | string | The name of the boolean property that controls visibility. |
order | int | The 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
| Name | Type | Description |
|---|---|---|
operatorType | EConditionOperator | Logical operator used to evaluate multiple conditions. |
order | int | The drawer order for rendering (optional). |
conditionNames | string[] | An array of condition property names. |