Class ShowIfAttribute
Attribute to show or hide a field based on a condition.
Note: If the target field is a bool it will check for true/false, otherwise it will check if the field is not null.
[SerializeField] private bool m_UseFeature;
[SerializeField, ShowIf("m_UseFeature")] private Transform m_ObjectReference; // Will only be visible if m_UseFeature is true.
Known Issue:
Sometimes the Inspector Window will not update the field when the condition is met.
Until solved, this behaviour can be fixed by deselecting and reselecting the item to refresh the inspector manually.
[AttributeUsage(AttributeTargets.Property|AttributeTargets.Field, Inherited = true, AllowMultiple = false)]
public class ShowIfAttribute : ConditionAttribute
- Inheritance
-
ShowIfAttribute
- Derived
Constructors
ShowIfAttribute(string, bool)
Attribute to show or hide a field based on a condition. (shown if condition is true)
public ShowIfAttribute(string fieldName, bool value = true)
Parameters
Properties
FieldName
public string FieldName { get; }
Property Value
Value
public bool Value { get; }
Property Value
Methods
EvaluateActive(object)
Override this method to calculate if the field is active or not.
public override bool EvaluateActive(object target)
Parameters
target
objectThe object to evaluate the condition for.
Returns
- bool
True if the field is active; otherwise false.
EvaluateReadOnly(object)
Override this method to calculate if the field is read only or not.
public override bool EvaluateReadOnly(object target)
Parameters
target
objectThe object to evaluate the condition for.
Returns
- bool
True if the field is read only; otherwise false.