Skip to content

Carousel

Snap-to-item scrollable container with slide, loop, and fade modes. A single CarouselView component handles both static-children and virtualized-with-pooling cases — virtualization kicks in when you register prefabs and an item count.

Inspector Setup

  1. Create a container with AutoLayout and AutoLayoutScrollView.
  2. Add the CarouselView component.
  3. For static mode: add child items as direct children of the carousel.
  4. For virtualized mode: register prefabs in the Prefabs list and set ItemCount via code.
FieldTypeDefaultDescription
DirectionCarouselDirectionHorizontalScroll axis
TypeCarouselTypeSlideSlide, Loop, or Fade
Per Pageint1Visible slides at once
FocusFocusModeCenterSnap alignment (Start, Center, End)
Paddingfloat0Edge padding in pixels
Gapfloat0Gap between items
Speedfloat400Transition speed in ms
Is RewindboolfalseWrap from last to first
Uniform Item Sizefloat0Fixed item size (0 = auto)
VirtualizedbooltrueEnable object pooling (only effective when prefabs are registered)
Overscan Countint2Extra items rendered offscreen
Default Pool Capacityint10Initial pool size per prefab type
PrefabsList-Prefab registrations (typeId + prefab + capacity)

Code Usage

AutoUI Builder — virtualized

AutoUI.Create()
.WidthFill().Height(300)
.Carousel(CarouselDirection.Horizontal)
.Type(CarouselType.Loop)
.PerPage(3)
.Focus(FocusMode.Center)
.Gap(16)
.Speed(400)
.Prefab(cardPrefab, 6)
.ItemCount(items.Count)
.GetItem(i => items[i])
.BindItem((go, index, data) =>
{
var label = go.GetComponentInChildren<TMP_Text>();
label.text = ((MyItem)data).Name;
})
.Capture(c =>
{
m_Carousel = c;
m_Carousel.OnFocusChanged += i => Debug.Log($"Focused: {i}");
})
.End()
.Build();

AutoUI Builder — static children

When you don’t register prefabs, the carousel hosts its declared .Children(...) directly:

AutoUI.Create()
.WidthFill().Height(200)
.Carousel(CarouselDirection.Horizontal)
.Focus(FocusMode.Center)
.Gap(12)
.Speed(300)
.Capture(c => m_Carousel = c)
.End()
.Children(
AutoUI.Create().Size(200, 180).Background(Color.red),
AutoUI.Create().Size(200, 180).Background(Color.blue),
AutoUI.Create().Size(200, 180).Background(Color.green)
)
.Build();

AddComponent Pattern

If you’d rather configure the CarouselView component directly:

AutoUI.Create()
.WidthFill().Height(380)
.Overflow(UIOverflow.Hidden)
.ScrollView(sv => { })
.AddComponent<CarouselView>(cv =>
{
cv.Direction = CarouselDirection.Horizontal;
cv.Type = CarouselType.Loop;
cv.PerPage = 3;
cv.Focus = FocusMode.Center;
cv.Gap = 20;
cv.RegisterPrefab(0, cardPrefab, 6);
cv.ItemCount = items.Count;
cv.BindItemCallback = (go, index, data) => { /* bind */ };
cv.RefreshItems();
})
.Build();

Methods

MethodDescription
GoToItem(int index, bool animated = true)Navigate to specific item
GoToNext(bool animated = true)Navigate forward
GoToPrevious(bool animated = true)Navigate backward
AddEffect(ICarouselEffect effect)Add visual scroll effect
RemoveEffect(ICarouselEffect effect)Remove visual effect
RefreshItems()Refresh after data change (virtualized only)
RefreshItemsImmediate()Synchronous refresh (virtualized only)

Properties

PropertyTypeDescription
FocusedIndexintCurrently focused item index
IsSnappingboolSnap animation in progress
IsDraggingboolUser is dragging
ItemCountintTotal number of items
ScrollProgressfloatContinuous scroll progress

Events (CarouselView component)

Subscribe via Capture after building:

EventSignatureDescription
OnFocusChangedAction<int>Fires when focused item changes
OnFocusChangingAction<int, int>Fires during transition (from, to)
OnScrollProgressAction<float>Continuous scroll progress updates

Callbacks (virtualized mode)

CallbackSignatureDescription
GetItemCallbackFunc<int, object>Return data for index
GetItemTypeCallbackFunc<int, int>Return prefab type for index
BindItemCallbackAction<GameObject, int, object>Bind data to item
UnbindItemCallbackAction<GameObject, int>Cleanup on recycle

Builder API

MethodDescription
.Type(CarouselType)Slide, Loop, or Fade
.Focus(FocusMode)Start, Center, End
.PerPage(int)Visible slides at once
.Gap(float)Gap between items
.Padding(float)Edge padding
.Speed(float)Transition speed in ms
.Rewind(bool)Wrap from last to first
.Easing(CarouselEasingFunction)Custom easing
.PoolCapacity(int)Default pool size per prefab
.Prefab(GameObject, int)Register type-0 prefab
.Prefab(int, GameObject, int)Register typed prefab
.Effect(ICarouselEffect)Add visual effect
.Delegate(ICarouselViewDelegate)Set delegate (overrides callbacks)
.ItemCount(int)Set total items
.GetItem(Func<int, object>)Set data callback
.BindItem(Action<GameObject, int, object>)Set bind callback
.UnbindItem(Action<GameObject, int>)Set unbind callback
.Capture(Action<CarouselView>)Capture reference (e.g. .Capture(c => m_Carousel = c))
.End()Return to parent LayoutBuilder

Interfaces

  • ICarouselItem — Implement on prefab root for auto-binding.
  • ICarouselViewDelegate — Full data source control (overrides callbacks).
  • ICarouselEffect — Custom visual effects applied during scroll.

Notes

  • The .Carousel(...) builder method returns a CarouselBuilder; finalize with .End() to keep chaining on the parent, or .Build() to materialise the tree.
  • Use Focus = Center for typical snap-to-center carousels; Start snaps the leading edge; End snaps the trailing edge.
  • .Type(CarouselType.Loop) enables wrap-around scrolling; Slide clamps at boundaries; Fade cross-fades between items.