Version 3.3.1.2

GenericSelector<T> class

Namespace: Sirenix.OdinInspector.Editor
Assembly: Sirenix.OdinInspector.Editor
public class GenericSelector<T> : OdinSelector<T>, ISelectionChangeListener
In simple one-off use cases, making a custom OdinSelector might not be needed, as the GenericSelecor can be populated with anything and customized a great deal.
Inheritance
Example
SomeType someValue;

[OnInspectorGUI]
void OnInspectorGUI()
{
    if (GUILayout.Button("Open Generic Selector Popup"))
    {
        List<SomeType> source = ...;
        GenericSelector<SomeType> selector = new GenericSelector<SomeType>("Title", false, x => x.Path, source);
        selector.SetSelection(this.someValue);
        selector.SelectionTree.Config.DrawSearchToolbar = false;
        selector.SelectionTree.DefaultMenuStyle.Height = 22;
        selector.SelectionConfirmed += selection => this.someValue = selection.FirstOrDefault()
        var window = selector.ShowInPopup();
        window.OnEndGUI += () => { EditorGUILayout.HelpBox("A quick way of injecting custom GUI to the editor window popup instance.", MessageType.Info); };
        window.OnClose += selector.SelectionTree.Selection.ConfirmSelection; // Confirm selection when window clses.
    }
}

Type Parameters

T

Constructors

GenericSelector(T[])
Initializes a new instance of the GenericSelector<T> class.
public GenericSelector(params T[] collection)
Parameters
T[] collection

GenericSelector(IEnumerable<T>)
Initializes a new instance of the GenericSelector<T> class.
public GenericSelector(IEnumerable<T> collection)
Parameters
System.Collections.Generic.IEnumerable<T> collection

GenericSelector(String, T[])
Initializes a new instance of the GenericSelector<T> class.
public GenericSelector(string title, params T[] collection)
Parameters
System.String title

T[] collection

GenericSelector(String, Boolean, T[])
Initializes a new instance of the GenericSelector<T> class.
public GenericSelector(string title, bool supportsMultiSelect, params T[] collection)
Parameters
System.String title

System.Boolean supportsMultiSelect

T[] collection

GenericSelector(String, Boolean, IEnumerable<T>)
Initializes a new instance of the GenericSelector<T> class.
public GenericSelector(string title, bool supportsMultiSelect, IEnumerable<T> collection)
Parameters
System.String title

System.Boolean supportsMultiSelect

System.Collections.Generic.IEnumerable<T> collection

GenericSelector(String, Boolean, IEnumerable<GenericSelectorItem<T>>)
public GenericSelector(string title, bool supportsMultiSelect, IEnumerable<GenericSelectorItem<T>> collection)
Parameters
System.String title

System.Boolean supportsMultiSelect

System.Collections.Generic.IEnumerable<GenericSelectorItem<T>> collection

GenericSelector(String, Boolean, Func<T, String>, T[])
Initializes a new instance of the GenericSelector<T> class.
public GenericSelector(string title, bool supportsMultiSelect, Func<T, string> getMenuItemName, params T[] collection)
Parameters
System.String title

System.Boolean supportsMultiSelect

System.Func<T, System.String> getMenuItemName

T[] collection

GenericSelector(String, Boolean, Func<T, String>, IEnumerable<T>)
Initializes a new instance of the GenericSelector<T> class.
public GenericSelector(string title, bool supportsMultiSelect, Func<T, string> getMenuItemName, IEnumerable<T> collection)
Parameters
System.String title

System.Boolean supportsMultiSelect

System.Func<T, System.String> getMenuItemName

System.Collections.Generic.IEnumerable<T> collection

GenericSelector(String, IEnumerable<T>)
Initializes a new instance of the GenericSelector<T> class.
public GenericSelector(string title, IEnumerable<T> collection)
Parameters
System.String title

System.Collections.Generic.IEnumerable<T> collection

GenericSelector(String, IEnumerable<T>, Boolean, Func<T, String>)
Initializes a new instance of the GenericSelector<T> class.
public GenericSelector(string title, IEnumerable<T> collection, bool supportsMultiSelect, Func<T, string> getMenuItemName = null)
Parameters
System.String title

System.Collections.Generic.IEnumerable<T> collection

System.Boolean supportsMultiSelect

System.Func<T, System.String> getMenuItemName

Properties

CheckboxToggle
Gets or sets a value indicating whether [checkbox toggle].
public bool CheckboxToggle { get; set; }
FlattenedTree
Gets or sets a value indicating whether [flattened tree].
public bool FlattenedTree { get; set; }
Title
Gets the title. No title will be drawn if the string is null or empty.
public override string Title { get; }

Methods

BuildSelectionTree(OdinMenuTree)
Builds the selection tree.
protected override void BuildSelectionTree(OdinMenuTree tree)
Parameters
OdinMenuTree tree

DrawSelectionTree()
Draws the selection tree. This gets drawn using the OnInspectorGUI attribute.
protected override void DrawSelectionTree()
GetCurrentSelection()
public override IEnumerable<T> GetCurrentSelection()
Returns
System.Collections.Generic.IEnumerable<T>

IsValidSelection(IEnumerable<T>)
public override bool IsValidSelection(IEnumerable<T> collection)
Parameters
System.Collections.Generic.IEnumerable<T> collection

Returns
System.Boolean

SetSelection(T)
public override void SetSelection(T selected)
Parameters
T selected

SetSelection(IEnumerable<T>)
public override void SetSelection(IEnumerable<T> selection)
Parameters
System.Collections.Generic.IEnumerable<T> selection