Class ConditionalAttributeBase
Abstract base class for all conditional Inspector attributes that show, hide, enable, or disable a serialized field based on the runtime value of another field on the same object.
Inheritance
Inherited Members
Namespace: Scylla.Core.Attributes
Assembly: ScyllaCore.dll
Syntax
public abstract class ConditionalAttributeBase : PropertyAttribute
Remarks
ConditionalAttributeBase captures the three pieces of information
needed to evaluate a condition at Inspector draw-time:
- ConditionField
The name of the serialized field whose value is read to evaluate the
condition. The field must be a serialized member of the same
MonoBehaviour,ScriptableObject, or serializable struct as the decorated field. - CompareValue
The value to compare the condition field against. When
null, the condition evaluates the truthiness of the field: non-zero numbers, non-null object references, and non-empty strings are consideredtrue. - Operator The CompareOperator used to relate the field value to CompareValue. Defaults to Equals when not explicitly specified.
Concrete subclasses that ship with the framework are ShowIfAttribute, HideIfAttribute, EnableIfAttribute, and DisableIfAttribute. Each subclass inherits the same set of constructor overloads defined here and differs only in how the custom Editor drawer reacts when the condition is met (hide vs. show, or disable vs. enable).
Custom conditional attributes can be created by deriving from this class and
providing an associated custom PropertyDrawer that reads these
properties and applies the desired Inspector behaviour.
Constructors
ConditionalAttributeBase(string)
Initializes a new conditional attribute that evaluates the truthiness of the specified field, without comparing it to an explicit value.
Declaration
protected ConditionalAttributeBase(string conditionField)
Parameters
| Type | Name | Description |
|---|---|---|
| string | conditionField | The name of the serialized field to evaluate. Use |
Remarks
This constructor sets CompareValue to null and
Operator to Equals. The custom
drawer will treat the condition as met whenever the field is truthy (non-zero,
non-null, non-empty). This is the most concise form and covers the common
case of toggling visibility or editability with a boolean field.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when |
ConditionalAttributeBase(string, object)
Initializes a new conditional attribute that compares the specified field to an explicit value using Equals.
Declaration
protected ConditionalAttributeBase(string conditionField, object compareValue)
Parameters
| Type | Name | Description |
|---|---|---|
| string | conditionField | The name of the serialized field to evaluate. Use |
| object | compareValue | The value to compare the field against using equality. Supports boxed
|
Remarks
This constructor sets Operator to Equals. Use the three-argument overload when a different comparison operator is required.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when |
ConditionalAttributeBase(string, object, CompareOperator)
Initializes a new conditional attribute that compares the specified field to an explicit value using a custom CompareOperator.
Declaration
protected ConditionalAttributeBase(string conditionField, object compareValue, CompareOperator op)
Parameters
| Type | Name | Description |
|---|---|---|
| string | conditionField | The name of the serialized field to evaluate. Use |
| object | compareValue | The value to compare the field against. Supports boxed |
| CompareOperator | op | The CompareOperator that determines how |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when |
Properties
CompareValue
Gets the value that ConditionField's runtime value is compared against using the Operator.
Declaration
public object CompareValue { get; }
Property Value
| Type | Description |
|---|---|
| object | The compare value supplied to the attribute constructor, or |
Remarks
When null, the custom drawer evaluates the truthiness of the
condition field rather than performing an explicit comparison. The following
values are treated as false in truthiness mode: numeric zero, null
object references, and empty or null strings. All other values are true.
ConditionField
Gets the name of the serialized field whose value is read when evaluating the condition.
Declaration
public string ConditionField { get; }
Property Value
| Type | Description |
|---|---|
| string | A non-null, non-empty string containing the exact C# field name (not the
display label) of the condition field. Use |
Remarks
The field identified by this name must be serialized - either declared
public or annotated with [SerializeField] - and it must be a
direct member of the same serialized object as the decorated field. Fields
on nested objects or parent types may not be resolvable depending on the
custom drawer implementation.
Operator
Gets the CompareOperator used to relate the runtime value of ConditionField to CompareValue.
Declaration
public CompareOperator Operator { get; }
Property Value
| Type | Description |
|---|---|
| CompareOperator | The operator specified in the attribute constructor. Defaults to Equals when the constructor overload that omits the operator is used. |
Remarks
Ordering operators such as LessThan and
GreaterThan are only meaningful for numeric
field types. BitwiseAnd is designed for
[System.Flags] enums and evaluates whether any of the specified flag
bits are set on the field.