UI Elements
Carousel
A sliding content carousel with animated transitions and indicators
Overview
Carousel displays a list of items that can be navigated manually or automatically. It supports animated slide transitions, indicators with progress timers, and click events on individual entries.
Items contain a title, description, background sprite, and custom click event. The component handles object creation, transition animation, indicator updates, and auto sliding based on a timer at runtime.
Properties
Content
| Name | Type | Description |
|---|---|---|
currentIndex | int | Currently active item index |
items | List<Item> | List of carousel entries |
Each item contains:
| Field | Type | Description |
|---|---|---|
title | string | Display name of the item |
description | string | Item description text |
background | Sprite | Background sprite used in the carousel preset |
onClick | UnityEvent | Event triggered when the item is clicked |
Settings
| Name | Type | Description |
|---|---|---|
useUnscaledTime | bool | Uses unscaled time for timers and animations |
autoSlide | bool | Enables automatic sliding |
autoSlideTimer | float | Time before moving to the next item |
animationCurve | AnimationCurve | Curve used for slide transitions |
animationDuration | float | Duration of slide animation |
indicatorShrink | float | Scale applied to inactive indicators |
slideOffset | Vector2 | Offset direction for slide animation |
References
| Name | Type | Description |
|---|---|---|
itemParent | Transform | Parent where item objects are created |
itemPreset | GameObject | Prefab with CarouselPreset component |
indicatorParent | Transform | Parent where indicator objects are created |
indicatorPreset | GameObject | Prefab with CarouselIndicator component |
Public Methods
| Name | Parameters | Description |
|---|---|---|
Initialize() | None | Creates objects, resets timer, and shows current item |
NextItem() | None | Slides to the next item |
PreviousItem() | None | Slides to the previous item |
GoToItem(index) | int | Slides to a specific item |
CurrentIndex | property | Returns the current item index |
IsTransitioning | property | Indicates if a slide animation is in progress |
Code Example
using UnityEngine;
using Evo.UI;
public class CarouselExample : MonoBehaviour
{
public Carousel carousel;
void Start()
{
// Change settings
carousel.autoSlide = true;
carousel.autoSlideTimer = 4f;
// Go to next item manually
carousel.NextItem();
// Go to previous item
carousel.PreviousItem();
// Jump to index
carousel.GoToItem(2);
// Read current index
Debug.Log("Current index: " + carousel.CurrentIndex);
}
}