Tabs
A flexible tab system with animated transitions and title display
Overview
Tabs is a tab and panel switching system that supports animated transitions, tab titles, UI navigation, and event callbacks. Each tab contains a content object, button reference, optional default selections, and full animation control.
The component handles showing the selected tab, hiding or disabling others, playing transition animations, updating the title display, remembering the last selected UI element, and reacting to multiple triggers (buttons, IDs, or external code).
Usage
Add Tabs component to a parent object
Create tab entries and assign:
- Tab ID for referencing by string
- Tab Object for content panels
- Tab Button to switch on click
- First Selected (optional) for controller/keyboard UI navigation
Set your Default Tab Index
Optionally assign Title Object for the tab name display
Click to the assigned tab button or call OpenTab() from code to switch manually
Properties
Tabs
| Field | Type | Description |
|---|---|---|
tabs | List<Item> | List of tab definitions |
defaultTabIndex | int | Index of the tab to open at Start |
tabID | string | Optional unique ID for string based switching |
tabObject | RectTransform | Content object for the tab |
tabButton | Button | Clicking this button opens the tab |
firstSelected | GameObject | First selected object for controller navigation |
latestSelected | GameObject | Automatically updated last selected object |
canvasGroup | CanvasGroup | Cached for animations |
originalAnchoredPosition | Vector2 | Used for restoring position during slide animations |
Animation
| Name | Type | Description |
|---|---|---|
animationType | AnimationType | None, Fade, Scale, SlideHorizontal, SlideVertical |
animationCurve | AnimationCurve | Easing curve for transitions |
animationDuration | float | Duration of the transition |
scaleOutMultiplier | float | Scale used when hiding the old tab |
scaleInMultiplier | float | Scale used when showing the new tab |
slideDistance | float | Slide offset applied during slide animations |
Title Display
| Name | Type | Description |
|---|---|---|
titleObject | TextMeshProUGUI | Text object used to display current tab name |
titleSlideCurve | AnimationCurve | Curve used when animating the title text |
titleSlideDuration | float | Total duration of title animation |
titleChangeDelay | float | Delay before the title text updates |
titleSlideOffset | Vector2 | Offset direction for slide out/in movement |
Settings
| Name | Type | Description |
|---|---|---|
useUnscaledTime | bool | Use real time instead of game time scale |
disableInvisibleTabs | bool | Completely disables tabs that are not selected |
Events
| Name | Type | Description |
|---|---|---|
onTabChanged | UnityEvent<int> | Triggered when a new tab becomes active |
Public Methods
| Name | Parameters | Description |
|---|---|---|
OpenTab(int index) | int | Switch to a tab by index |
OpenTab(string id) | string | Switch to a tab using its ID |
OpenFirstTab() | None | Shortcut for index 0 |
OpenLastTab() | None | Opens the last tab |
AddTab(item) | Item | Adds a new tab at runtime |
RemoveTab(index) | int | Removes a tab by index |
RemoveTab(id) | string | Removes a tab by ID |
CurrentTabIndex | property | Returns active tab index |
CurrentTabID | property | Returns active tab ID |
CurrentTab | property | Returns active Item reference |
Code Example
using UnityEngine;
using Evo.UI;
public class TabsExample : MonoBehaviour
{
public Tabs tabs;
void Start()
{
// Default behavior
tabs.OpenTab(0);
// Event: print the selected tab index
tabs.onTabChanged.AddListener(i =>
{
Debug.Log("Selected Tab Index: " + i);
});
// Configure tab transition
tabs.disableInvisibleTabs = true;
}
public void OpenInventoryTab()
{
tabs.OpenTab("Inventory");
}
public void OpenSettingsTab()
{
tabs.OpenTab("Settings");
}
public void NextTab()
{
tabs.OpenNextTab();
}
}