FieldConditionAttribute - Metimos/com.metimos.utilities GitHub Wiki
An attribute that can be used to conditionally show or hide a field in the inspector.
Passing the third parameter as false
will completely hide the field instead of disabling it.
Declaration
FieldCondition(string name, object value, bool visible = true)
Parameters
Parameter | Description |
---|---|
name | Which property or field to compare with - must be within the same scope of the attribute's field. |
value | The value to compare with the property or field. |
visible | Whether the field should remain visible, otherwise it will be disabled (greyed out). |
Example
public void Example : MonoBehaviour
{
[SerializeField]
private bool _showField = true;
// Will be active when _showField is true.
[SerializeField]
[FieldCondition(nameof(_showField), true)]
private int _onField = 0;
// Will be active when _showField is false.
[SerializeField]
[FieldCondition(nameof(_showField), false)]
private int _offField = 0;
}