// MIT License - Copyright (c) 2025 wallstop
// Full license text: https://github.com/wallstop/unity-helpers/blob/main/LICENSE
namespace WallstopStudios.UnityHelpers.Editor.CustomDrawers
{
#if UNITY_EDITOR && ODIN_INSPECTOR
using System;
using Sirenix.OdinInspector.Editor;
using UnityEditor;
using UnityEngine;
using WallstopStudios.UnityHelpers.Core.Attributes;
using WallstopStudios.UnityHelpers.Editor.CustomDrawers.Utils;
///
/// Odin Inspector attribute drawer for .
/// Renders fields decorated with WValueDropDown as dropdown selectors.
///
///
/// This drawer ensures WValueDropDown works correctly when Odin Inspector is installed
/// and classes derive from SerializedMonoBehaviour or SerializedScriptableObject,
/// where Unity's standard PropertyDrawer system is bypassed.
///
public sealed class WValueDropDownOdinDrawer : OdinAttributeDrawer
{
///
/// Draws the property as a dropdown selector with the options provided by the attribute.
///
/// The label to display for the property.
protected override void DrawPropertyLayout(GUIContent label)
{
WValueDropDownAttribute dropdownAttribute = Attribute;
if (dropdownAttribute == null)
{
CallNextDrawer(label);
return;
}
object parentValue = Property.Parent?.ValueEntry?.WeakSmartValue;
object[] options = dropdownAttribute.GetOptions(parentValue) ?? Array.Empty