DEV Community

Piler
Piler

Posted on

[Unity] Create Dropdown in PropertyDrawer

Offical example code:

public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
    index = EditorGUILayout.Popup(index, options);
}
Enter fullscreen mode Exit fullscreen mode

If you want to update property value after select:

public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
  int index = Array.IndexOf(options, property.objectReferenceValue);

  if (index!= -1)
  {
      index = EditorGUI.Popup(position, label.text, index, options);
      property.objectReferenceValue = options[index];
  }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)