Thank you for your answer, @MrMatthias
Following that documentation and loosely looking at this implementation (which I cannot use unfortunately), I came up with this:
using System;
using UnityEditor;
using UnityEngine;
[CustomPropertyDrawer(typeof(DropdownAttribute))]
public class DropdownAttributePropertyDrawer : PropertyDrawer
{
// Draw the property inside the given rect
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
DropdownAttribute dropdownAttribute = PropertyUtility.GetAttribute<DropdownAttribute>(property);
UnityEngine.Object target = PropertyUtility.GetTargetObject(property);
var value = ReflectionUtility.GetField(target, property.name).GetValue(target);
int index = Array.FindIndex(dropdownAttribute.Options, s => value.Equals(s));
var i = EditorGUI.Popup(position, index, Array.ConvertAll(dropdownAttribute.Options, s => s.ToString()));
ReflectionUtility.GetField(target, property.name).SetValue(target, dropdownAttribute.Options[i]);
}
}
Using PropertyUtility and ReflectionUtility.
Doesn’t seem to affect a field like this:
public class Test : BaseBehavior
{
[SerializeField]
[Dropdown("A", "B", "C", "D")]
public string S;
}
I use FullSerializer and I don’t know whether that’s the problem or somethign wrong with the code. I have never worked with these elements so it is hard to make sense of that code. I might look for a different solution, since this is a bit too much for me, I guess. If you see an obvious issue, I would be glad to receive a comment.