5#pragma warning disable IDE0130
7#pragma warning restore IDE0130
9 [CustomPropertyDrawer(typeof(EnableIfAttribute))]
10 internal sealed class EnableIfDrawer : PropertyDrawer
12 public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
17 var isEnabled = attribute is not EnableIfAttribute enableIf ||
18 ConditionalMemberEvaluator.ShouldEnable(property, enableIf);
20 EditorGUI.BeginProperty(position, label, property);
21 using (
new EditorGUI.DisabledScope(!isEnabled))
23 if (ConditionalMemberEvaluator.TryGetBuiltInDrawer(property, fieldInfo, out var builtInDrawer))
25 ConditionalMemberEvaluator.DrawBuiltInDrawer(builtInDrawer, position, property, label);
29 EditorGUI.PropertyField(position, property, label,
true);
33 EditorGUI.EndProperty();
36 public override float GetPropertyHeight(SerializedProperty property, GUIContent label) =>
37 ConditionalMemberEvaluator.TryGetBuiltInDrawer(property, fieldInfo, out var builtInDrawer)
38 ? ConditionalMemberEvaluator.GetBuiltInDrawerHeight(builtInDrawer, property, label)
39 : EditorGUI.GetPropertyHeight(property, label,
true);