Attribute that can be used to make class member that follows the attribute be shown as disabled (read-only) when a predicate statement is true.
DisableIf(string classMemberName, object requiredValue)
When this constructor is used, the target is disabled if the class member with the given name has the specified value.
DisableIf(string classMemberName, Is comparison, object requiredValue)
When this constructor is used, the target is disabled if the class member with the given name passes the comparison check against the specified value.
DisableIf(string classMemberName, string comparison, object requiredValue)
When this constructor is used, the target is disabled if the class member with the given name passes the comparison check against the specified value.
Accepted comparison values are: ==, !=, <, >, <= and >=. They mean equal, not equal, smaller than, larger than, smaller than or equal to and larger than or equal to respectively.
DisableIf(string booleanExpression)
When this constructor is used, the target is disabled if the boolean expression is true.
With this constructor it is possible to evaluate expressions containing multiple parts and containing conjunctions and parentheses.
Supported conjunctions are & (and) and | (or).
Attribute Target
Field, property, method or indexer.
Example
using System; using UnityEngine; using Sisus.Attributes; using JetBrains.Annotations; public class InstantiatePrefab : MonoBehaviour { [DisableIf(nameof(hasValidResourceTarget), true)] public GameObject prefab; [DisableIf(nameof(prefab), Is.Not, null)] public string prefabResourceName = ""; [HideInInspector, SerializeField] private bool hasValidResourceTarget; [ShowInInspector][NotNull] public GameObject Instantiate() { if(prefab != null) { return Instantiate(prefab); } if(hasValidResourceTarget) { return Instantiate(Resources.Load<GameObject>(prefabResourceName)); } throw new NullReferenceException(name + " - Both prefab and resource name missing!"); } [UsedImplicitly] private void OnValidate() { if(prefab != null) { var name = prefab.name; var tryLoad = Resources.Load<GameObject>(name); prefabResourceName = tryLoad != null ? name : ""; hasValidResourceTarget = false; } else { hasValidResourceTarget = prefabResourceName.Length > 0 && Resources.Load<GameObject>(prefabResourceName) != null; } } }