Version 3.3.1.2

OdinMenuTree class

Namespace: Sirenix.OdinInspector.Editor
Assembly: Sirenix.OdinInspector.Editor
public class OdinMenuTree : IEnumerable
OdinMenuTree provides a tree of OdinMenuItems, and helps with selection, inserting menu items into the tree, and can handle keyboard navigation for you.
Inheritance
  • System.Object
  • OdinMenuTree
Example
OdinMenuTree tree = new OdinMenuTree(supportsMultiSelect: true)
{
    { "Home",                           this,                           EditorIcons.House       },
    { "Odin Settings",                  null,                           SdfIconType.GearFill    },
    { "Odin Settings/Color Palettes",   ColorPaletteManager.Instance,   EditorIcons.EyeDropper  },
    { "Odin Settings/AOT Generation",   AOTGenerationConfig.Instance,   EditorIcons.SmartPhone  },
    { "Camera current",                 Camera.current                                          },
    { "Some Class",                     this.someData                                           }
};

tree.AddAllAssetsAtPath("Some Menu Item", "Some Asset Path", typeof(ScriptableObject), true)
    .AddThumbnailIcons();

tree.AddAssetAtPath("Some Second Menu Item", "SomeAssetPath/SomeAssetFile.asset");

var customMenuItem = new OdinMenuItem(tree, "Menu Style", tree.DefaultMenuStyle);
tree.MenuItems.Insert(2, customMenuItem);

tree.Add("Menu/Items/Are/Created/As/Needed", new GUIContent());
tree.Add("Menu/Items/Are/Created", new GUIContent("And can be overridden"));
OdinMenuTrees are typically used with OdinMenuEditorWindows but is made to work perfectly fine on its own for other use cases. OdinMenuItems can be inherited and and customized to fit your needs.
// Draw stuff
someTree.DrawMenuTree();
// Draw stuff
someTree.HandleKeybaordMenuNavigation();

Constructors

OdinMenuTree()
Initializes a new instance of the OdinMenuTree class.
public OdinMenuTree()
OdinMenuTree(Boolean)
Initializes a new instance of the OdinMenuTree class.
public OdinMenuTree(bool supportsMultiSelect)
Parameters
System.Boolean supportsMultiSelect

if set to true [supports multi select].

OdinMenuTree(Boolean, OdinMenuStyle)
Initializes a new instance of the OdinMenuTree class.
public OdinMenuTree(bool supportsMultiSelect, OdinMenuStyle defaultMenuStyle)
Parameters
System.Boolean supportsMultiSelect

if set to true [supports multi select].

OdinMenuStyle defaultMenuStyle

The default menu item style.

OdinMenuTree(Boolean, OdinMenuTreeDrawingConfig)
Initializes a new instance of the OdinMenuTree class.
public OdinMenuTree(bool supportsMultiSelect, OdinMenuTreeDrawingConfig config)
Parameters
System.Boolean supportsMultiSelect

OdinMenuTreeDrawingConfig config

Fields

ActiveMenuTree
Gets the currently active menu tree.
public static OdinMenuTree ActiveMenuTree
FlatMenuTree
public List<OdinMenuItem> FlatMenuTree

Properties

Config
Gets or sets the default drawing configuration.
public OdinMenuTreeDrawingConfig Config { get; set; }
DefaultMenuStyle
Gets or sets the default menu item style from Config.DefaultStyle.
public OdinMenuStyle DefaultMenuStyle { get; set; }
DrawInSearchMode
If true, all indent levels will be ignored, and all menu items with IsVisible == true will be drawn.
public bool DrawInSearchMode { get; }
MenuItems
Gets the root menu items.
public List<OdinMenuItem> MenuItems { get; }
RootMenuItem
Gets the root menu item.
public OdinMenuItem RootMenuItem { get; }
Selection
Gets the selection.
public OdinMenuTreeSelection Selection { get; }

Methods

Add(String, Object)
Adds a menu item with the specified object instance at the the specified path.
public void Add(string path, object instance)
Parameters
System.String path

System.Object instance

Add(String, Object, SdfIconType)
Adds a menu item with the specified object instance and icon at the the specified path.
public void Add(string path, object instance, SdfIconType icon)
Parameters
System.String path

System.Object instance

SdfIconType icon

Add(String, Object, EditorIcon)
Adds a menu item with the specified object instance and icon at the the specified path.
public void Add(string path, object instance, EditorIcon icon)
Parameters
System.String path

System.Object instance

EditorIcon icon

Add(String, Object, Sprite)
Adds a menu item with the specified object instance and icon at the the specified path.
public void Add(string path, object instance, Sprite sprite)
Parameters
System.String path

System.Object instance

UnityEngine.Sprite sprite

Add(String, Object, Texture)
Adds a menu item with the specified object instance and icon at the the specified path.
public void Add(string path, object instance, Texture icon)
Parameters
System.String path

System.Object instance

UnityEngine.Texture icon

AddRange<T>(IEnumerable<T>, Func<T, String>)
Adds a collection of objects to the menu tree and returns all menu items created in random order.
public IEnumerable<OdinMenuItem> AddRange<T>(IEnumerable<T> collection, Func<T, string> getPath)
Parameters
System.Collections.Generic.IEnumerable<T> collection

System.Func<T, System.String> getPath

Returns
System.Collections.Generic.IEnumerable<OdinMenuItem>

Type Parameters
T

AddRange<T>(IEnumerable<T>, Func<T, String>, Func<T, Texture>)
Adds a collection of objects to the menu tree and returns all menu items created in random order.
public IEnumerable<OdinMenuItem> AddRange<T>(IEnumerable<T> collection, Func<T, string> getPath, Func<T, Texture> getIcon)
Parameters
System.Collections.Generic.IEnumerable<T> collection

System.Func<T, System.String> getPath

System.Func<T, UnityEngine.Texture> getIcon

Returns
System.Collections.Generic.IEnumerable<OdinMenuItem>

Type Parameters
T

DrawMenuTree()
Draws the menu tree recursively.
public void DrawMenuTree()
DrawSearchToolbar(GUIStyle)
Draws the search toolbar.
public void DrawSearchToolbar(GUIStyle toolbarStyle = null)
Parameters
UnityEngine.GUIStyle toolbarStyle

EnumerateTree(Action<OdinMenuItem>)
Enumerates the tree with a DFS.
public void EnumerateTree(Action<OdinMenuItem> action)
Parameters
System.Action<OdinMenuItem> action

EnumerateTree(Boolean)
Enumerates the tree with a DFS.
public IEnumerable<OdinMenuItem> EnumerateTree(bool includeRootNode = false)
Parameters
System.Boolean includeRootNode

if set to true then the invisible root menu item is included.

Returns
System.Collections.Generic.IEnumerable<OdinMenuItem>

EnumerateTree(Func<OdinMenuItem, Boolean>, Boolean)
Enumerates the tree with a DFS.
public IEnumerable<OdinMenuItem> EnumerateTree(Func<OdinMenuItem, bool> predicate, bool includeRootNode)
Parameters
System.Func<OdinMenuItem, System.Boolean> predicate

The predicate.

System.Boolean includeRootNode

if set to true then the invisible root menu item is included.

Returns
System.Collections.Generic.IEnumerable<OdinMenuItem>

FocusSearchField()
Sets the focus to the Sirenix.OdinInspector.Editor.OdinMenuTree.searchField.
public void FocusSearchField()
HandleKeyboardMenuNavigation()
Handles the keyboard menu navigation. Call this at the end of your GUI scope, to prevent the menu tree from stealing input events from other text fields.
public bool HandleKeyboardMenuNavigation()
Returns
System.Boolean

Returns true, if anything was changed via the keyboard.

MarkDirty()
Marks the dirty. This will cause a tree.UpdateTree() in the beginning of the next Layout frame.
public void MarkDirty()
MarkLayoutChanged()
Indicates that the layout has changed and needs to be recomputed. This is used when EXPERIMENTAL_INTERNAL_SparseFixedLayouting is enabled.
public void MarkLayoutChanged()
ScrollToMenuItem(OdinMenuItem, Boolean)
Scrolls to the specified menu item.
public void ScrollToMenuItem(OdinMenuItem menuItem, bool centerMenuItem = false)
Parameters
OdinMenuItem menuItem

System.Boolean centerMenuItem

UpdateMenuTree()
Updates the menu tree. This method is usually called automatically when needed.
public void UpdateMenuTree()
Extension Methods