using UnityEditor; using UnityEngine; [CustomPropertyDrawer(typeof(DropdownAttribute))] public class DropdownDrawer : PropertyDrawer { public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { DropdownAttribute dropdownAttribute = attribute as DropdownAttribute; if (property.propertyType == SerializedPropertyType.String) { int selectedIndex = Mathf.Max(0, System.Array.IndexOf(dropdownAttribute.options, property.stringValue)); selectedIndex = EditorGUI.Popup(position, label.text, selectedIndex, dropdownAttribute.options); property.stringValue = dropdownAttribute.options[selectedIndex]; } else { EditorGUI.LabelField(position, label.text, "Use Dropdown with string."); } } }