A feature-rich enum selector with support for flag enums.

namespace Sirenix.OdinInspector.Editor
public class EnumSelector<T> : OdinSelector<T>


Namespace: Sirenix.OdinInspector.Editor
Assembly: Sirenix.OdinInspector

See Also

Static Methods

Return Type Definition Description
T DrawEnumField(GUIContent, T) Draws an enum selector field using the enum selector.


Definition Description
EnumSelector() Initializes a new instance of the EnumSelector<T> class.


Return Type Definition Description
bool IsFlagEnum Gets a value indicating whether this instance is flag enum.
string Title By default, the enum type will be drawn as the title for the selector. No title will be drawn if the string is null or empty.


Return Type Definition Description
void BuildSelectionTree(OdinMenuTree) Populates the tree with all enum values.
float DefaultWindowWidth() When ShowInPopup is called, without a specified window width, this method gets called. Here you can calculate and give a good default width for the popup. The default implementation returns 0, which will let the popup window determine the width itself. This is usually a fixed value.
IEnumerable<T> GetCurrentSelection() Gets the currently selected enum value.
void SetSelection(T) Selects an enum.


KeyCode someEnumValue;

void OnInspectorGUI()
    // Use the selector manually. See the documentation for OdinSelector for more information.
    if (GUILayout.Button("Open Enum Selector"))
        EnumSelector<KeyCode> selector = new EnumSelector<KeyCode>();
        selector.SelectionConfirmed += selection => this.someEnumValue = selection.FirstOrDefault();
        selector.ShowInPopup(); // Returns the Odin Editor Window instance, in case you want to mess around with that as well.
    // Draw an enum dropdown field which uses the EnumSelector popup:
    this.someEnumValue = EnumSelector<KeyCode>.DrawEnumField(new GUIContent("My Label"), this.someEnumValue);

// All Odin Selectors can be rendered anywhere with Odin. This includes the EnumSelector.
EnumSelector<KeyCode> inlineSelector;

EnumSelector<KeyCode> InlineSelector
    get { return this.inlineSelector ?? (this.inlineSelector = new EnumSelector<KeyCode>()); }
    set { }