Space Ad Mobile 9.5.1
Space Ad Mobile makes ads easy to add into your mobile game: one unified workflow for LevelPlay, AdMob, Yandex.Ads across banners, interstitials and rewarded.
Loading...
Searching...
No Matches
EnableIfDrawer.cs
1#if UNITY_EDITOR
2using UnityEditor;
3using UnityEngine;
4
5#pragma warning disable IDE0130
6namespace SCG.Editor
7#pragma warning restore IDE0130
8{
9 [CustomPropertyDrawer(typeof(EnableIfAttribute))]
10 internal sealed class EnableIfDrawer : PropertyDrawer
11 {
12 public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
13 {
14 if (property == null)
15 return;
16
17 var isEnabled = attribute is not EnableIfAttribute enableIf ||
18 ConditionalMemberEvaluator.ShouldEnable(property, enableIf);
19
20 EditorGUI.BeginProperty(position, label, property);
21 using (new EditorGUI.DisabledScope(!isEnabled))
22 {
23 if (ConditionalMemberEvaluator.TryGetBuiltInDrawer(property, fieldInfo, out var builtInDrawer))
24 {
25 ConditionalMemberEvaluator.DrawBuiltInDrawer(builtInDrawer, position, property, label);
26 }
27 else
28 {
29 EditorGUI.PropertyField(position, property, label, true);
30 }
31 }
32
33 EditorGUI.EndProperty();
34 }
35
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);
40 }
41}
42#endif