Files
com.misaki.ao-volume/Editor/PropertyDrawer/PopupBooleanDrawer.cs
Misaki 2f79df128e Improved the culling result of HizCulling;
Added custom inspector for VolumeObject;
Change the name of AoVolume to VolumeObject;
2025-02-24 00:22:04 +09:00

36 lines
1.2 KiB
C#

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<bool> _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<bool>(property.displayName, _popupOptions, false);
popupField.AddToClassList(PopupField<bool>.alignedFieldUssClassName);
popupField.bindingPath = property.propertyPath;
return popupField;
}
}
}