EnumSelector<T>

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

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

Requirements

Namespace: Sirenix.OdinInspector.Editor
Assembly: Sirenix.OdinInspector
Version: 2.0.0.0

See Also

Static Methods

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

Constructors

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

Properties

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.

Methods

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.

Example

KeyCode someEnumValue;

[OnInspectorGUI]
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.SetSelection(this.someEnumValue);
        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;

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