Menu Bar
A traditional top-bar menu for showing options
Overview
Menu Bar creates a traditional application-style menu system that appears as a horizontal bar at the top of your interface. It supports multiple menu items, each with dropdown submenus, icons, and custom actions.
The component automatically generates buttons for each menu item, manages menu opening/closing behavior, and supports hover-to-open functionality. It uses the Context Menu component internally to handle dropdown menus.
Usage
Add Menu Bar component to a UI object
Add bar items to the Items list
Configure menu items for each bar item
Make sure Item Parent and Item Preset are assigned
Menu will appear when clicked or hovered
Make sure the Item Parent object has a Horizontal Layout Group (or a similar component) to align the buttons properly.
Customize Preset
- Locate the default presets in the References foldout
- Open the Item Preset prefab and customize the button appearance
- Open the Context Menu Preset prefab and customize the dropdown style
Create New Presets
You can create different Menu Bar presets and use them on different interfaces. To create a new preset:
- Locate the default presets in the References foldout
- Duplicate the Item Preset and Context Menu Preset
- Open the new prefabs and customize them to your liking
- Assign the new presets to your Menu Bar component
Properties
Item List
| Name | Type | Description |
|---|---|---|
items | List<BarItem> | List of menu bar items that appear horizontally |
Each bar item has:
| Field | Type | Description |
|---|---|---|
label | string | Text displayed on the menu bar button |
icon | Sprite | Optional icon displayed next to the label |
tableKey | string | Localization key for translating the label (if enabled) |
menuBarItems | List<ContextMenu.Item> | Dropdown menu items that appear when clicking this bar item |
onClick | UnityEvent | Invoked when clicking the bar item button |
Settings
| Name | Type | Description |
|---|---|---|
openMenuOnHover | bool | Opens dropdown menu when hovering over items (instead of requiring click) |
blockUIWhileOpen | bool | Blocks other UI interaction while a dropdown menu is open |
itemMenuOffset | Vector2 | Offset applied to dropdown menu position relative to button |
Animation
| Name | Type | Description |
|---|---|---|
animationType | AnimationType | None, Fade, Scale, or Slide animation for dropdown menus |
animationDuration | float | Duration of show and hide animations |
animationCurve | AnimationCurve | Curve controlling ease in and out |
scaleFrom | float | Starting scale used in Scale mode |
slideOffset | Vector2 | Offset direction used in Slide mode |
References
| Name | Type | Description |
|---|---|---|
itemParent | Transform | Container where bar item buttons are instantiated |
itemPreset | GameObject | Prefab used to create each menu bar button |
contextMenuPreset | GameObject | Prefab used for dropdown menus |
Public Methods
| Name | Parameters | Description |
|---|---|---|
Initialize() | None | Builds the menu bar by instantiating buttons and context menus |
OpenMenu(targetBarItem) | BarItem | Opens the dropdown menu for the specified bar item |
CloseMenu() | None | Closes the currently open dropdown menu |
Code Example
using UnityEngine;
using Evo.UI;
public class MenuBarExample : MonoBehaviour
{
public MenuBar menuBar;
void Start()
{
// Add a new menu item programmatically
var fileMenu = new MenuBar.BarItem
{
label = "File",
menuBarItems = new()
{
new Evo.UI.ContextMenu.Item
{
itemName = "New",
itemType = Evo.UI.ContextMenu.Item.ItemType.Button,
onClick = new UnityEngine.Events.UnityEvent()
},
new Evo.UI.ContextMenu.Item
{
itemName = "Open",
itemType = Evo.UI.ContextMenu.Item.ItemType.Button,
onClick = new UnityEngine.Events.UnityEvent()
},
new Evo.UI.ContextMenu.Item
{
itemType = Evo.UI.ContextMenu.Item.ItemType.Separator
},
new Evo.UI.ContextMenu.Item
{
itemName = "Exit",
itemType = Evo.UI.ContextMenu.Item.ItemType.Button,
onClick = new UnityEngine.Events.UnityEvent()
}
}
};
// Add listeners
fileMenu.menuBarItems[0].onClick.AddListener(() =>
{
Debug.Log("New file created");
});
fileMenu.menuBarItems[1].onClick.AddListener(() =>
{
Debug.Log("Opening file");
});
fileMenu.onClick.AddListener(() =>
{
Debug.Log("File menu clicked");
});
menuBar.items.Add(fileMenu);
// Reinitialize to apply changes
menuBar.Initialize();
// Configure settings
menuBar.openMenuOnHover = true;
menuBar.blockUIWhileOpen = true;
}
// Example: programmatically open a menu
public void OpenFileMenu()
{
if (menuBar.items.Count > 0)
{
menuBar.OpenMenu(menuBar.items[0]);
}
}
// Example: programmatically close menu
public void CloseCurrentMenu()
{
menuBar.CloseMenu();
}
}