Version 2.1.0.0

EnumSelector<T> class

Namespace: Sirenix.OdinInspector.Editor
Assembly: Sirenix.OdinInspector.Editor
public class EnumSelector<T> : OdinSelector<T>
A feature-rich enum selector with support for flag enums.
Inheritance
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 { }
}

Type Parameters

T

Constructors

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

Fields

DrawSearchToolbar
public static bool DrawSearchToolbar

Properties

IsFlagEnum
Gets a value indicating whether this instance is flag enum.
public bool IsFlagEnum { get; }
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.
public override string Title { get; }

Methods

BuildSelectionTree(OdinMenuTree)
Populates the tree with all enum values.
protected override void BuildSelectionTree(OdinMenuTree tree)
Parameters
OdinMenuTree tree

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.
protected override float DefaultWindowWidth()
Returns
System.Single

DrawEnumField(GUIContent, T, GUIStyle)
Draws an enum selector field using the enum selector.
public static T DrawEnumField(GUIContent label, T value, GUIStyle style = null)
Parameters
UnityEngine.GUIContent label

T value

UnityEngine.GUIStyle style

Returns
T

DrawEnumField(GUIContent, GUIContent, T, GUIStyle)
Draws an enum selector field using the enum selector.
public static T DrawEnumField(GUIContent label, GUIContent contentLabel, T value, GUIStyle style = null)
Parameters
UnityEngine.GUIContent label

UnityEngine.GUIContent contentLabel

T value

UnityEngine.GUIStyle style

Returns
T

DrawEnumField(Rect, GUIContent, T, GUIStyle)
Draws an enum selector field using the enum selector.
public static T DrawEnumField(Rect rect, GUIContent label, T value, GUIStyle style = null)
Parameters
UnityEngine.Rect rect

UnityEngine.GUIContent label

T value

UnityEngine.GUIStyle style

Returns
T

DrawEnumField(Rect, GUIContent, GUIContent, T, GUIStyle)
Draws an enum selector field using the enum selector.
public static T DrawEnumField(Rect rect, GUIContent label, GUIContent contentLabel, T value, GUIStyle style = null)
Parameters
UnityEngine.Rect rect

UnityEngine.GUIContent label

UnityEngine.GUIContent contentLabel

T value

UnityEngine.GUIStyle style

Returns
T

GetCurrentSelection()
Gets the currently selected enum value.
public override IEnumerable<T> GetCurrentSelection()
Returns
System.Collections.Generic.IEnumerable<T>

SetSelection(T)
Selects an enum.
public override void SetSelection(T selected)
Parameters
T selected