Show or hide fields dynamically based on runtime values.
The [WShowIf] attribute creates dynamic inspector layouts that adapt to field values without writing custom PropertyDrawers. Perfect for reducing clutter, creating a contextual UI, and guiding designers toward valid configurations.
usingUnityEngine;usingWallstopStudios.UnityHelpers.Core.Attributes;publicclassWeaponConfig:MonoBehaviour{publicboolisRanged;[WShowIf(nameof(isRanged))]publicfloatprojectileSpeed=10f;// Only visible when isRanged == true[WShowIf(nameof(isRanged), inverse: true)]publicfloatmeleeRange=2f;// Only visible when isRanged == false}
publicenumWeaponType{Melee,Ranged,Magic}publicWeaponTypeweaponType;[WShowIf(nameof(weaponType), WShowIfComparison.Equal, WeaponType.Ranged)]publicintammoCapacity=30;[WShowIf(nameof(weaponType), WShowIfComparison.NotEqual, WeaponType.Melee)]publicfloatcastTime=1f;// Visible for Ranged or Magic
publicGameObjecttargetPrefab;[WShowIf(nameof(targetPrefab), WShowIfComparison.IsNotNull)]publicintspawnCount=1;[WShowIf(nameof(targetPrefab), WShowIfComparison.IsNull)]publicstringwarningMessage="Assign a prefab to spawn!";
publicList<GameObject>enemies;[WShowIf(nameof(enemies), WShowIfComparison.IsNotNullOrEmpty)]publicfloatspawnInterval=2f;[WShowIf(nameof(enemies), WShowIfComparison.IsNullOrEmpty)]publicstringhint="Add enemies to the list";
publicbooluseCustomColor;// Show when useCustomColor == false[WShowIf(nameof(useCustomColor), inverse: true)]publicstringcolorPreset="Default";// Show when useCustomColor == true[WShowIf(nameof(useCustomColor))]publicColorcustomColor=Color.white;
publicenumGameState{MainMenu,Playing,Paused,GameOver}publicGameStatestate;// Show when state is Playing OR Paused[WShowIf(nameof(state), WShowIfComparison.Equal, GameState.Playing, GameState.Paused)]publicfloatgameTimer;// Show when state is MainMenu OR GameOver[WShowIf(nameof(state), WShowIfComparison.Equal, GameState.MainMenu, GameState.GameOver)]publicstringmenuText;
publicboolisEnabled;publicintlevel;// Both conditions must be true (AND logic)[WShowIf(nameof(isEnabled))][WShowIf(nameof(level), WShowIfComparison.GreaterThan, 5)]publicAbilityadvancedFeature;
Note: Multiple [WShowIf] attributes create AND logic (all must be true).
publicclassEnemy:MonoBehaviour{publicfloathealth=100f;// Property (computed)publicboolIsAlive=>health>0f;// Show when IsAlive == true[WShowIf(nameof(IsAlive))]publicfloatdamageResistance=0.5f;// Method (no parameters)publicboolShouldShowDebug()=>Application.isEditor&&Debug.isDebugBuild;[WShowIf(nameof(ShouldShowDebug))]publicstringdebugInfo;}
Supported:
Public fields
Public properties (with getter)
Public methods returning bool/int/float/enum/string/object (no parameters)
// ✅ GOOD: Show hint when condition is falsepublicGameObjectweaponPrefab;[WShowIf(nameof(weaponPrefab), WShowIfComparison.IsNull)]publicstringhint="⚠️ Assign a weapon prefab above";[WShowIf(nameof(weaponPrefab), WShowIfComparison.IsNotNull)]publicintweaponDamage=10;// ❌ BAD: No indication why fields are missing[WShowIf(nameof(weaponPrefab), WShowIfComparison.IsNotNull)]publicintweaponDamage=10;// User may not realize they need to assign prefab
usingUnityEngine;usingWallstopStudios.UnityHelpers.Core.Attributes;publicclassAIController:MonoBehaviour{publicboolenableAI=true;[WShowIf(nameof(enableAI), inverse: true)]publicstringdisabledMessage="AI is disabled";[WShowIf(nameof(enableAI))]publicfloatdetectionRange=10f;[WShowIf(nameof(enableAI))]publicfloatattackRange=2f;[WShowIf(nameof(enableAI))]publicboolcanFlee=true;[WShowIf(nameof(canFlee))][WShowIf(nameof(enableAI))]publicfloatfleeHealthThreshold=0.3f;}