[EnableIf]
Enables user interaction with a serialized field, property, or button only when a specified condition evaluates to true (greying it out otherwise).
1. Overview & Value Proposition
What it does: Keeps dependent settings visible so designers know they exist, but locks them interactively in a disabled state until criteria are satisfied.
The Problem: In standard Unity, secondary fields sit wide open even when their parent feature flag is turned off. Game designers adjust phantom values that have no effect, causing confusing bug reports.
The Solution:
- Prerequisite Enforcement: Visually greys out fields until conditions evaluate to true.
- Disabled Tooltips: Shows why a field is locked (e.g.
DisabledTooltip = "Requires Level 10!"). - Inline Expressions: Supports compound comparisons like
[EnableIf("$playerLevel >= 10 && $isLicensed")]. - Zero Polling: Directly binds to UI Toolkit visual change events with zero per-frame recalculations.
2. Quick Start Example
using UnityEngine;
using MaharajaStudio.MSUltimate.Runtime;
public class CharacterShield : MonoBehaviour
{
public bool hasEnergyShield = true;
// 1. Basic Boolean Toggle with Custom Tooltip
[EnableIf(nameof(hasEnergyShield), DisabledTooltip = "Enable Energy Shield to edit capacity!")]
public float maxShieldCapacity = 100f;
// 2. Compound Inline Expression
[EnableIf("$hasEnergyShield && $maxShieldCapacity > 50")]
public float shieldRechargeRate = 12.5f;
}
3. Customization Options & Properties
| Property | Type | Default | Description |
|---|---|---|---|
Condition |
string |
*Required* | Member name, method name, or compound C# expression (prefixed with $). |
DisabledTooltip |
string |
null |
Custom hover tooltip shown when the field is greyed out. |
TargetValue |
object |
true |
Target value to compare against when matching enum or integer values. |
Core Framework Architecture & Staged Attributes
156+ Attributes Staged in Workspace
All 156+ core attributes, custom serializers, and window systems are organized inside assets/Documentations/MSUltimate/Documentation/attributes/. The two reference attributes above demonstrate the complete documentation standard.