Class EditableIfAttribute
Attribute to make a field editable if a condition is met.
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, EditableIf("m_UseFeature")] private Transform m_ObjectReference; // Will only be editable if m_UseFeature is true.
[AttributeUsage(AttributeTargets.Property|AttributeTargets.Field, Inherited = true, AllowMultiple = false)]
public class EditableIfAttribute : ShowIfAttribute
- Inheritance
-
EditableIfAttribute
- Inherited Members
Constructors
EditableIfAttribute(string, bool)
Attribute to make a field editable if a condition is met.
public EditableIfAttribute(string fieldName, bool value = true)
Parameters
EditableIfAttribute(string, int, bool)
Attribute to make a field editable if a condition is met. [Enum]
[SerializeField]
private SomeEnum m_Enum;
[SerializeField, EditableIf(nameof(m_Enum), (int)SomeEnum.Option2)]
private Transform m_ObjectReference; // Will only be editable if m_Enum is Option2.
public EditableIfAttribute(string fieldName, int enumValue, bool isEqualTo = true)
Parameters
fieldNamestringThe name of the field to check.
enumValueintThe enum value to check for (as an int).
isEqualToboolIf the field should be editable if the enum value is equal or inequal to the provided value.
Methods
EvaluateActive(object)
Override this method to calculate if the field is active or not.
public override bool EvaluateActive(object target)
Parameters
targetobjectThe 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
targetobjectThe object to evaluate the condition for.
Returns
- bool
True if the field is read only; otherwise false.