using UnityEditor; using UnityEngine; namespace Funique { [CustomPropertyDrawer(typeof(HideIf))] public class HideIfDrawer : IfDrawerBase { public override void OnGUI(Rect position, SerializedProperty p, GUIContent label) { HideIf a = (HideIf)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("[HideIf] Invalid Property Name for Attribute.", p.serializedObject.targetObject); else newState = t.boolValue != a.DisabledState; if (newState) EditorGUI.PropertyField(position, p, label, true); } public override float GetPropertyHeight(SerializedProperty p, GUIContent label) { HideIf a = (HideIf)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("[HideIf] Invalid Property Name for Attribute.", p.serializedObject.targetObject); else newState = t.boolValue != a.DisabledState; if (newState) return EditorGUI.GetPropertyHeight(p, true); else return 0; } } }