using UnityEditor; using UnityEngine; namespace Funique { [CustomPropertyDrawer(typeof(DisableIf))] public class DisableIfDrawer : IfDrawerBase { public override void OnGUI(Rect position, SerializedProperty p, GUIContent label) { DisableIf a = (DisableIf)attribute; bool havesomethingtodetect = a.Target != string.Empty; SerializedProperty t = GetPointer(a.Target, p); bool newState = true; bool oldState = GUI.enabled; if (!havesomethingtodetect) newState = !a.DisabledState; else if (t == null) Debug.LogWarning("[DisableIf] Invalid Property Name for Attribute.", p.serializedObject.targetObject); else newState = t.boolValue != a.DisabledState; GUI.enabled = newState; EditorGUI.PropertyField(position, p, label, true); GUI.enabled = oldState; } public override float GetPropertyHeight(SerializedProperty p, GUIContent label) { return EditorGUI.GetPropertyHeight(p, true); } } }