DEV Community

Piler
Piler

Posted on

1

[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)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay