using System.Collections.Generic; using UnityEditor; using UnityEngine; using UnityEngine.UIElements; namespace Misaki.AoVolume.Editor { [CustomPropertyDrawer(typeof(PopupBooleanAttribute))] public class PopupBooleanDrawer : PropertyDrawer { private static readonly GUIContent[] _popupContent = { new("False"), new("True") }; private static readonly List _popupOptions = new() { false, true }; public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { var value = property.boolValue; var index = value ? 1 : 0; EditorGUI.BeginChangeCheck(); index = EditorGUI.Popup(position, label, index, _popupContent); if (EditorGUI.EndChangeCheck()) { property.boolValue = index == 1; } } public override VisualElement CreatePropertyGUI(SerializedProperty property) { var popupField = new PopupField(property.displayName, _popupOptions, false); popupField.AddToClassList(PopupField.alignedFieldUssClassName); popupField.bindingPath = property.propertyPath; return popupField; } } }