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
Create a container with AutoLayout and AutoLayoutScrollView.
Add the CarouselView component.
For static mode: add child items as direct children of the carousel.
For virtualized mode: register prefabs in the Prefabs list and set ItemCount via code.
Field Type Default Description Direction CarouselDirection Horizontal Scroll axis Type CarouselType Slide Slide, Loop, or Fade Per Page int 1 Visible slides at once Focus FocusMode Center Snap alignment (Start, Center, End) Padding float 0 Edge padding in pixels Gap float 0 Gap between items Speed float 400 Transition speed in ms Is Rewind bool false Wrap from last to first Uniform Item Size float 0 Fixed item size (0 = auto) Virtualized bool true Enable object pooling (only effective when prefabs are registered) Overscan Count int 2 Extra items rendered offscreen Default Pool Capacity int 10 Initial pool size per prefab type Prefabs List - Prefab registrations (typeId + prefab + capacity)
Code Usage
AutoUI Builder — virtualized
. Carousel (CarouselDirection.Horizontal)
. BindItem (( go , index , data ) =>
var label = go. GetComponentInChildren < TMP_Text >();
label.text = (( MyItem )data).Name;
m_Carousel.OnFocusChanged += i => Debug. Log ( $"Focused: { i }" );
AutoUI Builder — static children
When you don’t register prefabs, the carousel hosts its declared .Children(...) directly:
. Carousel (CarouselDirection.Horizontal)
. Capture ( c => m_Carousel = c)
AutoUI. Create (). Size ( 200 , 180 ). Background (Color.red),
AutoUI. Create (). Size ( 200 , 180 ). Background (Color.blue),
AutoUI. Create (). Size ( 200 , 180 ). Background (Color.green)
AddComponent Pattern
If you’d rather configure the CarouselView component directly:
. Overflow (UIOverflow.Hidden)
. AddComponent < CarouselView >( cv =>
cv.Direction = CarouselDirection.Horizontal;
cv.Type = CarouselType.Loop;
cv.Focus = FocusMode.Center;
cv. RegisterPrefab ( 0 , cardPrefab, 6 );
cv.ItemCount = items.Count;
cv.BindItemCallback = ( go , index , data ) => { /* bind */ };
Methods
Method Description 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
Property Type Description FocusedIndexint Currently focused item index IsSnappingbool Snap animation in progress IsDraggingbool User is dragging ItemCountint Total number of items ScrollProgressfloat Continuous scroll progress
Events (CarouselView component)
Subscribe via Capture after building:
Event Signature Description OnFocusChangedAction<int>Fires when focused item changes OnFocusChangingAction<int, int>Fires during transition (from, to) OnScrollProgressAction<float>Continuous scroll progress updates
Callbacks (virtualized mode)
Callback Signature Description 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
Method Description .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.