using UnityEngine;
namespace EditorAttributes
{
public enum ConditionType
{
AND,
OR,
NAND,
NOR
}
public enum ConditionResult
{
ShowHide,
EnableDisable
}
///
/// Attribute to show/hide or disable/enable a field based on a bunch of conditions
///
public class ConditionalFieldAttribute : PropertyAttribute
{
public string[] BooleanNames { get; private set; }
public bool[] NegatedValues { get; private set; }
public ConditionType ConditionType { get; private set; }
public ConditionResult ConditionResult { get; private set; }
///
/// Attribute to show/hide or disable/enable a field based on a bunch of conditions
///
/// How to evaluate the the specified booleans
/// The names of the booleans to evaluate
public ConditionalFieldAttribute(ConditionType conditionType, params string[] booleanNames)
#if UNITY_2023_3_OR_NEWER
: base(true)
#endif
{
BooleanNames = booleanNames;
ConditionType = conditionType;
ConditionResult = ConditionResult.ShowHide;
}
///
/// Attribute to show/hide or disable/enable a field based on a bunch of conditions
///
/// How to evaluate the the specified booleans
/// What happens to the property when the condition evaluates to true
/// The names of the booleans to evaluate
public ConditionalFieldAttribute(ConditionType conditionType, ConditionResult conditionResult, params string[] booleanNames)
#if UNITY_2023_3_OR_NEWER
: base(true)
#endif
{
BooleanNames = booleanNames;
ConditionType = conditionType;
ConditionResult = conditionResult;
}
///
/// Attribute to show/hide or disable/enable a field based on a bunch of conditions
///
/// How to evaluate the the specified booleans
/// Specify which booleans to negate
/// The names of the booleans to evaluate
public ConditionalFieldAttribute(ConditionType conditionType, bool[] negatedValues, params string[] booleanNames)
#if UNITY_2023_3_OR_NEWER
: base(true)
#endif
{
BooleanNames = booleanNames;
NegatedValues = negatedValues;
ConditionType = conditionType;
ConditionResult = ConditionResult.ShowHide;
}
///
/// Attribute to show/hide or disable/enable a field based on a bunch of conditions
///
/// How to evaluate the the specified booleans
/// Specify which booleans to negate
/// What happens to the property when the condition evaluates to true
/// The names of the booleans to evaluate
public ConditionalFieldAttribute(ConditionType conditionType, ConditionResult conditionResult, bool[] negatedValues, params string[] booleanNames)
#if UNITY_2023_3_OR_NEWER
: base(true)
#endif
{
BooleanNames = booleanNames;
NegatedValues = negatedValues;
ConditionType = conditionType;
ConditionResult = conditionResult;
}
}
}