Logo
UI Elements

Dropdown

A highly customizable dropdown list

Overview

Dropdown displays a list of selectable items inside an animated panel. It supports icons, auto positioning based on screen space, and multiple animation types such as fade, scale, and slide.

Preview


Customize Item

  • Locate the default item prefab in the References foldout
  • Open the prefab and customize it as needed

Create New Prefabs

You can create different item prefabs and use them on different dropdowns. To create a new item prefab:

  • Locate the default item prefab in the References foldout
  • Duplicate the prefab (this is the fastest way to customize)
  • Open the new prefab and customize it to your liking

Properties

Item List

NameTypeDescription
selectedIndexintIndex of currently selected item
itemsList<Item>List of dropdown items

Item Layout

NameTypeDescription
itemSpacingintVertical spacing between item buttons
itemHeightfloatHeight of each item button
paddingRectOffsetInner padding of the items area

Settings

NameTypeDescription
scrollbarPositionScrollbarPositionScrollbar positioning method
maxHeightfloatMaximum scroll view height
blockUIWhileOpenboolCreates a fullscreen blocker behind dropdown
closeOnItemSelectboolCloses dropdown on item selection
closeOnClickOutsideboolCloses dropdown when clicking outside
rotateArrowboolRotates arrow when dropdown opens
arrowRotationfloatRotation applied when open

Animation

NameTypeDescription
animationTypeAnimationTypeFade, Scale, or Slide
animationDurationfloatDuration of open and close animations
animationCurveAnimationCurveControls easing behavior

References

NameTypeDescription
itemPrefabGameObjectPrefab for item entries
itemParentTransformParent transform for item objects
headerButtonButtonHeader button controlling open and close
headerArrowImageArrow graphic on header (optional)
scrollRectScrollRectScroll view containing items
canvasGroupCanvasGroupControls visibility and fading

Events

NameTypeDescription
onItemSelectedUnityEvent<int>Called when an item is selected
onOpenUnityEventCalled when dropdown opens
onCloseUnityEventCalled when dropdown closes

Public Methods

NameParametersDescription
Toggle()NoneOpens or closes dropdown
Open()NoneOpens dropdown with animation
Close()NoneCloses dropdown with animation
UpdateUI()NoneUpdates header and layout
SelectItem(index, triggerEvents)int, boolSelects item at index
SelectItem(item, triggerEvents)Item, boolSelects item by reference
SelectItem(label, triggerEvents)string, boolSelects item by label
AddItem(item, generate)Item, boolAdds item optionally generating UI
AddItem(label, icon, generate)string, Sprite, boolAdds item by label and icon
AddItems(newItems)params Item[]Adds multiple items
AddItems(labels)params string[]Adds multiple string items
RemoveItem(index)intRemoves item at index
RemoveItem(label)stringRemoves item by label
ClearAllItems()NoneRemoves all items
SortAlphabetically(ascending)boolSorts items

Code Example

DropdownExample.cs
using UnityEngine;
using Evo.UI;

public class DropdownExample : MonoBehaviour
{
    public Dropdown dropdown;

    void Start()
    {
        // Add item
        dropdown.AddItem("New Item");

        // Add item with icon
        Sprite myIcon = null;
        dropdown.AddItem("New Item", myIcon);

        // Add items
        dropdown.AddItems("Option A", "Option B", "Option C");

        // Remove items
        dropdown.RemoveItem("Item Label"); // using label
        dropdown.RemoveItem(0); // using index

        // Open event
        dropdown.onOpen.AddListener(() =>
        {
            Debug.Log("Dropdown opened");
        });

        // Close event
        dropdown.onClose.AddListener(() =>
        {
            Debug.Log("Dropdown closed");
        });

        // Select event
        dropdown.onItemSelected.AddListener(index =>
        {
            Debug.Log("Selected index: " + index);
        });

        // Manually select item
        dropdown.SelectItem(1);

        // Open dropdown
        dropdown.Open();
    }
}

On this page