Version 3.1.11.0

TypeSelector class

Namespace: Sirenix.OdinInspector.Editor
Assembly: Sirenix.OdinInspector.Editor
public class TypeSelector : OdinSelector<Type>
A feature-rich type selector.
Inheritance
Example
Type[] selectedTypes;

void OnGUI()
{
    // Use the selector manually. See the documentation for OdinSelector for more information.
    if (GUILayout.Button("Open My Selector"))
    {
        TypeSelector selector = new TypeSelector(customListOfTypes);
        TypeSelector selector = new TypeSelector(AssemblyTypeFlags.CustomTypes, supportsMultiSelect: true);
        selector.SetSelection(this.selectedTypes);
        selector.SelectionConfirmed += selection => this.selectedTypes = selection.ToArray();
        selector.ShowInPopup(); // Returns the Odin Editor Window instance, in case you want to mess around with that as well.
    }
}
Example
private static Type currentSelectedType;
private static IEnumerable<Type> currentSource;
private static Func<Rect, OdinSelector<Type>> createTypeSelector = (rect) =>
{
    TypeSelector selector = new TypeSelector(currentSource, false);
    selector.SetSelection(currentSelectedType);
    selector.ShowInPopup(rect);
    return selector;
};

public static Type DrawTypeSelectorDropdown(GUIContent label, Type selectedType, IEnumerable<Type> source)
{
    currentSource = source;
    currentSelectedType = selectedType;

    var dropdownText = selectedType == null ? "None" : selectedType.GetNiceName();
    var selected = TypeSelector.DrawSelectorDropdown(label, dropdownText, createTypeSelector);
    if (selected != null && selected.Any())
    {
        selectedType = selected.FirstOrDefault();
    }
    return selectedType;
}

Constructors

TypeSelector(AssemblyTypeFlags, Boolean)
public TypeSelector(AssemblyTypeFlags assemblyFlags, bool supportsMultiSelect)
Parameters
AssemblyTypeFlags assemblyFlags

System.Boolean supportsMultiSelect

TypeSelector(IEnumerable<Type>, Boolean)
public TypeSelector(IEnumerable<Type> types, bool supportsMultiSelect)
Parameters
System.Collections.Generic.IEnumerable<System.Type> types

System.Boolean supportsMultiSelect

Fields

FlattenTree
public bool FlattenTree
HideNamespaces
public bool HideNamespaces

Properties

Title
public override string Title { get; }

Methods

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

DefaultWindowWidth()
450
protected override float DefaultWindowWidth()
Returns
System.Single

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

Returns
System.Boolean

SetSelection(Type)
Sets the selected types.
public override void SetSelection(Type selected)
Parameters
System.Type selected