OdinMenuTree

OdinMenuTree provides a tree of OdinMenuItems, and helps with selection, inserting menu items into the tree, and can handle keyboard navigation for you.

namespace Sirenix.OdinInspector.Editor
{
public class OdinMenuTree : IEnumerable
}

Requirements

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

See Also

Static Fields

Return Type Definition Description
OdinMenuTree ActiveMenuTree Gets the currently active menu tree.

Constructors

Definition Description
OdinMenuTree() Initializes a new instance of the OdinMenuTree class.
OdinMenuTree(bool) Initializes a new instance of the OdinMenuTree class.
OdinMenuTree(bool, OdinMenuStyle) Initializes a new instance of the OdinMenuTree class.
OdinMenuTree(bool, OdinMenuTreeDrawingConfig) Initializes a new instance of the OdinMenuTree class.

Properties

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

Methods

Return Type Definition Description
void Add(string, Object) Adds a menu item with the specified object instance at the the specified path.
void Add(string, Object, EditorIcon) Adds a menu item with the specified object instance and icon at the the specified path.
void Add(string, Object, Sprite) Adds a menu item with the specified object instance and icon at the the specified path.
void Add(string, Object, Texture) Adds a menu item with the specified object instance and icon at the the specified path.
IEnumerable<OdinMenuItem> 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.
IEnumerable<OdinMenuItem> 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.
void DrawMenuTree() Draws the menu tree recursively.
void DrawSearchToolbar(GUIStyle) Draws the search toolbar.
void EnumerateTree(Action<OdinMenuItem>) Enumerates the tree with a DFS.
IEnumerable<OdinMenuItem> EnumerateTree(bool) Enumerates the tree with a DFS.
IEnumerable<OdinMenuItem> EnumerateTree(Func<OdinMenuItem, bool>, bool) Enumerates the tree with a DFS.
bool HandleKeybaordMenuNavigation() Handles the keybaord menu navigation. Call this at the end of your GUI scope, to prevent the menu tree from stealing input events from text fields and such.
void MarkDirty() Marks the dirty. This will cause a tree.UpdateTree() in the beginning of the next Layout frame.
void ScrollToMenuItem(OdinMenuItem, bool) Scrolls to the specified menu item.
void UpdateMenuTree() Updates the menu tree. This method is usually called automatically when needed.

Example

OdinMenuTree tree = new OdinMenuTree(supportsMultiSelect: true)
{
    { "Home",                           this,                           EditorIcons.House       },
    { "Odin Settings",                  null,                           EditorIcons.SettingsCog },
    { "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();