Version 3.3.0.1

OdinMenuTreeExtensions class

Namespace: Sirenix.OdinInspector.Editor
Assembly: Sirenix.OdinInspector.Editor
public static class OdinMenuTreeExtensions
Class with utility methods for OdinMenuTrees and OdinMenuItems.
Inheritance
  • System.Object
  • OdinMenuTreeExtensions
Example
OdinMenuTree tree = new OdinMenuTree();
tree.AddAllAssetsAtPath("Some Menu Item", "Some Asset Path", typeof(ScriptableObject), true)
    .AddThumbnailIcons();
tree.AddAssetAtPath("Some Second Menu Item", "SomeAssetPath/SomeAssetFile.asset");
// etc...

Methods

AddAllAssetsAtPath(OdinMenuTree, String, String, Boolean, Boolean)
Adds all assets at the specified path. Each asset found gets its own menu item inside the specified menu item path.
public static IEnumerable<OdinMenuItem> AddAllAssetsAtPath(this OdinMenuTree tree, string menuPath, string assetFolderPath, bool includeSubDirectories = false, bool flattenSubDirectories = false)
Parameters
OdinMenuTree tree

The tree.

System.String menuPath

The menu item path.

System.String assetFolderPath

The asset folder path.

System.Boolean includeSubDirectories

Whether to search for assets in subdirectories as well.

System.Boolean flattenSubDirectories

If true, sub-directories in the assetFolderPath will no longer get its own sub-menu item at the specified menu item path.

Returns
System.Collections.Generic.IEnumerable<OdinMenuItem>

Returns all menu items created in order to add the menu item at the specified menu item path.

AddAllAssetsAtPath(OdinMenuTree, String, String, Type, Boolean, Boolean)
Adds all assets at the specified path. Each asset found gets its own menu item inside the specified menu item path.
public static IEnumerable<OdinMenuItem> AddAllAssetsAtPath(this OdinMenuTree tree, string menuPath, string assetFolderPath, Type type, bool includeSubDirectories = false, bool flattenSubDirectories = false)
Parameters
OdinMenuTree tree

The tree.

System.String menuPath

The menu item path.

System.String assetFolderPath

The asset folder path.

System.Type type

The type.

System.Boolean includeSubDirectories

Whether to search for assets in subdirectories as well.

System.Boolean flattenSubDirectories

If true, sub-directories in the assetFolderPath will no longer get its own sub-menu item at the specified menu item path.

Returns
System.Collections.Generic.IEnumerable<OdinMenuItem>

Returns all menu items created in order to add the menu item at the specified menu item path.

AddAllAssetsAtPathCombined(OdinMenuTree, String, String, Type, Boolean)
Adds all asset instances from the specified path and type into a single OdinMenuItem at the specified menu item path, and returns all menu items created in order to add the menuItem at the specified path..
public static IEnumerable<OdinMenuItem> AddAllAssetsAtPathCombined(this OdinMenuTree tree, string menuPath, string assetFolderPath, Type type, bool includeSubDirectories = false)
Parameters
OdinMenuTree tree

The tree.

System.String menuPath

The menu item path.

System.String assetFolderPath

The asset folder path.

System.Type type

The type of objects.

System.Boolean includeSubDirectories

Whether to search for assets in subdirectories as well.

Returns
System.Collections.Generic.IEnumerable<OdinMenuItem>

Returns all menu items created in order to add the menu item at the specified menu item path.

AddAssetAtPath(OdinMenuTree, String, String)
Adds the asset at the specified menu item path and returns all menu items created in order to end up at the specified menu path.
public static IEnumerable<OdinMenuItem> AddAssetAtPath(this OdinMenuTree tree, string menuItemPath, string assetPath)
Parameters
OdinMenuTree tree

The tree.

System.String menuItemPath

The menu item path.

System.String assetPath

The asset path.

Returns
System.Collections.Generic.IEnumerable<OdinMenuItem>

Returns all menu items created in order to add the menu item at the specified menu item path.

AddAssetAtPath(OdinMenuTree, String, String, Type)
Adds the asset at the specified menu item path and returns all menu items created in order to end up at the specified menu path.
public static IEnumerable<OdinMenuItem> AddAssetAtPath(this OdinMenuTree tree, string menuItemPath, string assetPath, Type type)
Parameters
OdinMenuTree tree

The tree.

System.String menuItemPath

The menu item path.

System.String assetPath

The asset path.

System.Type type

The type.

Returns
System.Collections.Generic.IEnumerable<OdinMenuItem>

Returns all menu items created in order to add the menu item at the specified menu item path.

AddIcon(OdinMenuItem, SdfIconType)
Assigns the specified icon to the last menu item in the collection.
public static OdinMenuItem AddIcon(this OdinMenuItem menuItem, SdfIconType icon)
Parameters
OdinMenuItem menuItem

SdfIconType icon

Returns
OdinMenuItem

AddIcon(IEnumerable<OdinMenuItem>, EditorIcon)
Assigns the specified icon to the last menu item in the collection.
public static IEnumerable<OdinMenuItem> AddIcon(this IEnumerable<OdinMenuItem> menuItems, EditorIcon icon)
Parameters
System.Collections.Generic.IEnumerable<OdinMenuItem> menuItems

EditorIcon icon

Returns
System.Collections.Generic.IEnumerable<OdinMenuItem>

AddIcon(IEnumerable<OdinMenuItem>, Sprite)
Assigns the specified icon to the last menu item in the collection.
public static IEnumerable<OdinMenuItem> AddIcon(this IEnumerable<OdinMenuItem> menuItems, Sprite icon)
Parameters
System.Collections.Generic.IEnumerable<OdinMenuItem> menuItems

UnityEngine.Sprite icon

Returns
System.Collections.Generic.IEnumerable<OdinMenuItem>

AddIcon(IEnumerable<OdinMenuItem>, Texture)
Assigns the specified icon to the last menu item in the collection.
public static IEnumerable<OdinMenuItem> AddIcon(this IEnumerable<OdinMenuItem> menuItems, Texture icon)
Parameters
System.Collections.Generic.IEnumerable<OdinMenuItem> menuItems

UnityEngine.Texture icon

Returns
System.Collections.Generic.IEnumerable<OdinMenuItem>

AddIcon(IEnumerable<OdinMenuItem>, Texture, Texture)
Assigns the specified icon to the last menu item in the collection.
public static IEnumerable<OdinMenuItem> AddIcon(this IEnumerable<OdinMenuItem> menuItems, Texture icon, Texture iconSelected)
Parameters
System.Collections.Generic.IEnumerable<OdinMenuItem> menuItems

UnityEngine.Texture icon

UnityEngine.Texture iconSelected

Returns
System.Collections.Generic.IEnumerable<OdinMenuItem>

AddIcons(IEnumerable<OdinMenuItem>, EditorIcon)
Assigns the specified icon to all menu items in the collection.
public static IEnumerable<OdinMenuItem> AddIcons(this IEnumerable<OdinMenuItem> menuItems, EditorIcon icon)
Parameters
System.Collections.Generic.IEnumerable<OdinMenuItem> menuItems

EditorIcon icon

Returns
System.Collections.Generic.IEnumerable<OdinMenuItem>

AddIcons(IEnumerable<OdinMenuItem>, Func<OdinMenuItem, Sprite>)
Assigns the specified icon to all menu items in the collection.
public static IEnumerable<OdinMenuItem> AddIcons(this IEnumerable<OdinMenuItem> menuItems, Func<OdinMenuItem, Sprite> getIcon)
Parameters
System.Collections.Generic.IEnumerable<OdinMenuItem> menuItems

System.Func<OdinMenuItem, UnityEngine.Sprite> getIcon

Returns
System.Collections.Generic.IEnumerable<OdinMenuItem>

AddIcons(IEnumerable<OdinMenuItem>, Func<OdinMenuItem, Texture>)
Assigns the specified icon to all menu items in the collection.
public static IEnumerable<OdinMenuItem> AddIcons(this IEnumerable<OdinMenuItem> menuItems, Func<OdinMenuItem, Texture> getIcon)
Parameters
System.Collections.Generic.IEnumerable<OdinMenuItem> menuItems

System.Func<OdinMenuItem, UnityEngine.Texture> getIcon

Returns
System.Collections.Generic.IEnumerable<OdinMenuItem>

AddIcons(IEnumerable<OdinMenuItem>, Texture)
Assigns the specified icon to all menu items in the collection.
public static IEnumerable<OdinMenuItem> AddIcons(this IEnumerable<OdinMenuItem> menuItems, Texture icon)
Parameters
System.Collections.Generic.IEnumerable<OdinMenuItem> menuItems

UnityEngine.Texture icon

Returns
System.Collections.Generic.IEnumerable<OdinMenuItem>

AddIcons(IEnumerable<OdinMenuItem>, Texture, Texture)
Assigns the specified icon to all menu items in the collection.
public static IEnumerable<OdinMenuItem> AddIcons(this IEnumerable<OdinMenuItem> menuItems, Texture icon, Texture iconSelected)
Parameters
System.Collections.Generic.IEnumerable<OdinMenuItem> menuItems

UnityEngine.Texture icon

UnityEngine.Texture iconSelected

Returns
System.Collections.Generic.IEnumerable<OdinMenuItem>

AddIcons<T>(IEnumerable<OdinMenuItem>, Func<T, Sprite>)
Assigns the specified icon to all menu items in the collection with the specified ObjectInstanceType.
public static IEnumerable<OdinMenuItem> AddIcons<T>(this IEnumerable<OdinMenuItem> menuItems, Func<T, Sprite> getIcon)
Parameters
System.Collections.Generic.IEnumerable<OdinMenuItem> menuItems

System.Func<T, UnityEngine.Sprite> getIcon

Returns
System.Collections.Generic.IEnumerable<OdinMenuItem>

Type Parameters
T

AddIcons<T>(IEnumerable<OdinMenuItem>, Func<T, Texture>)
Assigns the specified icon to all menu items in the collection with the specified ObjectInstanceType.
public static IEnumerable<OdinMenuItem> AddIcons<T>(this IEnumerable<OdinMenuItem> menuItems, Func<T, Texture> getIcon)
Parameters
System.Collections.Generic.IEnumerable<OdinMenuItem> menuItems

System.Func<T, UnityEngine.Texture> getIcon

Returns
System.Collections.Generic.IEnumerable<OdinMenuItem>

Type Parameters
T

AddMenuItemAtPath(OdinMenuTree, ICollection<OdinMenuItem>, String, OdinMenuItem)
Adds the menu item at the specified menu item path and populates the result list with all menu items created in order to add the menuItem at the specified path.
public static void AddMenuItemAtPath(this OdinMenuTree tree, ICollection<OdinMenuItem> result, string path, OdinMenuItem menuItem)
Parameters
OdinMenuTree tree

The tree instance.

System.Collections.Generic.ICollection<OdinMenuItem> result

The result list.

System.String path

The menu item path.

OdinMenuItem menuItem

The menu item.

AddMenuItemAtPath(OdinMenuTree, String, OdinMenuItem)
Adds the menu item at specified menu item path, and returns all menu items created in order to add the menuItem at the specified path.
public static IEnumerable<OdinMenuItem> AddMenuItemAtPath(this OdinMenuTree tree, string path, OdinMenuItem menuItem)
Parameters
OdinMenuTree tree

The tree.

System.String path

The menu item path.

OdinMenuItem menuItem

The menu item.

Returns
System.Collections.Generic.IEnumerable<OdinMenuItem>

Returns all menu items created in order to add the menu item at the specified menu item path.

AddObjectAtPath(OdinMenuTree, String, Object, Boolean)
Adds the specified object at the specified menu item path and returns all menu items created in order to end up at the specified menu path.
public static IEnumerable<OdinMenuItem> AddObjectAtPath(this OdinMenuTree tree, string menuPath, object instance, bool forceShowOdinSerializedMembers = false)
Parameters
OdinMenuTree tree

The tree.

System.String menuPath

The menu path.

System.Object instance

The object instance.

System.Boolean forceShowOdinSerializedMembers

Set this to true if you want Odin serialzied members such as dictionaries and generics to be shown as well.

Returns
System.Collections.Generic.IEnumerable<OdinMenuItem>

Returns all menu items created in order to add the menu item at the specified menu item path.

AddThumbnailIcon(OdinMenuItem, Boolean)
Assigns the asset mini thumbnail as an icon to all menu items in the collection. If the menu items object is null then a Unity folder icon is assigned.
public static OdinMenuItem AddThumbnailIcon(this OdinMenuItem item, bool preferAssetPreviewAsIcon)
Parameters
OdinMenuItem item

System.Boolean preferAssetPreviewAsIcon

Returns
OdinMenuItem

AddThumbnailIcons(IEnumerable<OdinMenuItem>, Boolean)
Assigns the asset mini thumbnail as an icon to all menu items in the collection. If the menu items object is null then a Unity folder icon is assigned.
public static IEnumerable<OdinMenuItem> AddThumbnailIcons(this IEnumerable<OdinMenuItem> menuItems, bool preferAssetPreviewAsIcon = false)
Parameters
System.Collections.Generic.IEnumerable<OdinMenuItem> menuItems

System.Boolean preferAssetPreviewAsIcon

Returns
System.Collections.Generic.IEnumerable<OdinMenuItem>

AssignIconToEmptyItems(OdinMenuTree, SdfIconType, Nullable<Color>)
public static void AssignIconToEmptyItems(this OdinMenuTree tree, SdfIconType icon, Color? iconColor = default(Color? ))
Parameters
OdinMenuTree tree

SdfIconType icon

System.Nullable<UnityEngine.Color> iconColor

AssignIconToItemsWithNone(OdinMenuTree, SdfIconType, Nullable<Color>)
public static void AssignIconToItemsWithNone(this OdinMenuTree tree, SdfIconType icon, Color? iconColor = default(Color? ))
Parameters
OdinMenuTree tree

SdfIconType icon

System.Nullable<UnityEngine.Color> iconColor

CollapseEmptyItems(OdinMenuTree)
public static void CollapseEmptyItems(this OdinMenuTree tree)
Parameters
OdinMenuTree tree

GetMenuItem(OdinMenuTree, String)
Gets the menu item at the specified path, returns null non was found.
public static OdinMenuItem GetMenuItem(this OdinMenuTree tree, string menuPath)
Parameters
OdinMenuTree tree

System.String menuPath

Returns
OdinMenuItem

SortMenuItemsByName(OdinMenuTree, Boolean)
Sorts the entire tree of menu items recursively by name with respects to numbers.
public static IEnumerable<OdinMenuItem> SortMenuItemsByName(this OdinMenuTree tree, bool placeFoldersFirst = true)
Parameters
OdinMenuTree tree

System.Boolean placeFoldersFirst

Returns
System.Collections.Generic.IEnumerable<OdinMenuItem>

SortMenuItemsByName(IEnumerable<OdinMenuItem>, Boolean, Boolean, Boolean, Boolean)
Sorts the collection of menu items recursively by name with respects to numbers. This is a stable sort, meaning that equivalently ordered items will remain in the same order as they start.
public static IEnumerable<OdinMenuItem> SortMenuItemsByName(this IEnumerable<OdinMenuItem> menuItems, bool placeFoldersFirst = true, bool ignoreLeadingZeroes = true, bool ignoreWhiteSpace = true, bool ignoreCase = false)
Parameters
System.Collections.Generic.IEnumerable<OdinMenuItem> menuItems

System.Boolean placeFoldersFirst

System.Boolean ignoreLeadingZeroes

System.Boolean ignoreWhiteSpace

System.Boolean ignoreCase

Returns
System.Collections.Generic.IEnumerable<OdinMenuItem>

SortMenuItemsByName(IEnumerable<OdinMenuItem>, Comparison<OdinMenuItem>)
Sorts the collection of menu items recursively using a given custom comparison. This is a stable sort, meaning that equivalently ordered items will remain in the same order as they start.
public static IEnumerable<OdinMenuItem> SortMenuItemsByName(this IEnumerable<OdinMenuItem> menuItems, Comparison<OdinMenuItem> comparison)
Parameters
System.Collections.Generic.IEnumerable<OdinMenuItem> menuItems

System.Comparison<OdinMenuItem> comparison

Returns
System.Collections.Generic.IEnumerable<OdinMenuItem>