Logo
UI Elements

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.

Preview

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

NameTypeDescription
itemsList<BarItem>List of menu bar items that appear horizontally

Each bar item has:

FieldTypeDescription
labelstringText displayed on the menu bar button
iconSpriteOptional icon displayed next to the label
tableKeystringLocalization key for translating the label (if enabled)
menuBarItemsList<ContextMenu.Item>Dropdown menu items that appear when clicking this bar item
onClickUnityEventInvoked when clicking the bar item button

Settings

NameTypeDescription
openMenuOnHoverboolOpens dropdown menu when hovering over items (instead of requiring click)
blockUIWhileOpenboolBlocks other UI interaction while a dropdown menu is open
itemMenuOffsetVector2Offset applied to dropdown menu position relative to button

Animation

NameTypeDescription
animationTypeAnimationTypeNone, Fade, Scale, or Slide animation for dropdown menus
animationDurationfloatDuration of show and hide animations
animationCurveAnimationCurveCurve controlling ease in and out
scaleFromfloatStarting scale used in Scale mode
slideOffsetVector2Offset direction used in Slide mode

References

NameTypeDescription
itemParentTransformContainer where bar item buttons are instantiated
itemPresetGameObjectPrefab used to create each menu bar button
contextMenuPresetGameObjectPrefab used for dropdown menus

Public Methods

NameParametersDescription
Initialize()NoneBuilds the menu bar by instantiating buttons and context menus
OpenMenu(targetBarItem)BarItemOpens the dropdown menu for the specified bar item
CloseMenu()NoneCloses the currently open dropdown menu

Code Example

MenuBarExample.cs
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();
    }
}

On this page