ScrollView Variants
Coding Style wiki
InfiniteScrollView ships with 4 implementations (all inheriting InfiniteScrollView) — attach the matching component to the ScrollRect object and assign cellPrefab to use it; see the base class page for the shared APIs (initialization, data operations, refreshing, scrolling, and snapping).
| Namespace | OxGKit.InfiniteScrollView |
| Type | VerticalInfiniteScrollView, HorizontalInfiniteScrollView, VerticalGridInfiniteScrollView, HorizontalGridInfiniteScrollView (all inherit InfiniteScrollView) |
| Source | VerticalInfiniteScrollView.cs, HorizontalInfiniteScrollView.cs, VerticalGridInfiniteScrollView.cs, HorizontalGridInfiniteScrollView.cs |
using OxGKit.InfiniteScrollView;
Quick Start
Variants Overview
| Implementation | Layout | Specific Members |
|---|---|---|
| VerticalInfiniteScrollView | Vertical list (scrolls up and down) | spacing (float) |
| HorizontalInfiniteScrollView | Horizontal list (scrolls left and right) | spacing (float) |
| VerticalGridInfiniteScrollView | Vertical grid (scrolls up and down) | spacing (Vector2), columnCount |
| HorizontalGridInfiniteScrollView | Horizontal grid (scrolls left and right) | spacing (Vector2), rowCount |
using Cysharp.Threading.Tasks;
using OxGKit.InfiniteScrollView;
using UnityEngine;
public class GridLauncher : MonoBehaviour
{
public VerticalGridInfiniteScrollView gridScrollView;
private async void Start()
{
// Grid setup (also configurable on the Inspector)
this.gridScrollView.columnCount = 4;
this.gridScrollView.spacing = new Vector2(10f, 10f);
await this.gridScrollView.InitializePool();
for (int i = 0; i < 500; i++)
this.gridScrollView.Add(new InfiniteCellData(new Vector2(100f, 100f), i));
this.gridScrollView.Refresh();
}
}
General Rules
- The 4 implementations only differ in layout calculation and their specific members; data operations, refreshing, and snapping all share the base class behaviors.
- The list does not configure the
ScrollRectscroll axis automatically — set theScrollRect's Vertical / Horizontal checkboxes to match the implementation you use.
Attention The grid implementations advance the layout and content-size calculation using the cellSize of the first data entry of each row/column strip, so a uniform cellSize is recommended for grids (dynamic sizes are suited to the Vertical / Horizontal lists).
VerticalInfiniteScrollView
Vertical infinite list (scrolls up and down); suited to leaderboards, chat rooms, and other vertical lists.
| Type | public class VerticalInfiniteScrollView : InfiniteScrollView |
| Source | VerticalInfiniteScrollView.cs |
| Member | Description |
|---|---|
public float spacing | Vertical spacing between cells. |
Overridden Behaviors
public override void Snap(int index, float duration)
public override bool Remove(int index, bool refresh = true)
Snap: calculates the vertical target position by accumulatingcellSize.y + spacingaccording tosnapAlign(no-op when the content height is smaller than the viewport and cannot scroll).Remove: after removal, the content position is shifted back by one cell (cellSize.y + spacing) to avoid a visual jump.
HorizontalInfiniteScrollView
Horizontal infinite list (scrolls left and right); suited to card rows, horizontal menus, and other horizontal lists.
| Type | public class HorizontalInfiniteScrollView : InfiniteScrollView |
| Source | HorizontalInfiniteScrollView.cs |
| Member | Description |
|---|---|
public float spacing | Horizontal spacing between cells. |
Overridden Behaviors
public override void Snap(int index, float duration)
public override bool Remove(int index, bool refresh = true)
Snap: calculates the horizontal target position by accumulatingcellSize.x + spacingaccording tosnapAlign(no-op when the content width is smaller than the viewport and cannot scroll).Remove: after removal, the content position is shifted back by one cell (cellSize.x + spacing).
Reminder Tab-page (TabPage) usage can combine a horizontal list with Snap to switch pages (see the Infinite TabPage Demo in Samples, listed in the Module Intro).
VerticalGridInfiniteScrollView
Vertical grid infinite list (scrolls up and down) with columnCount cells side by side per row; suited to inventories, shops, and other grid lists.
| Type | public class VerticalGridInfiniteScrollView : InfiniteScrollView |
| Source | VerticalGridInfiniteScrollView.cs |
| Member | Description |
|---|---|
public Vector2 spacing | Cell spacing (x = horizontal, y = vertical). |
public int columnCount | Column count (cells side by side per row), default 1 (values less than or equal to 0 are treated as 1). |
Overridden Behaviors
public override void Snap(int index, float duration)
Snap: calculates the vertical target position from the row the target index belongs to (index / columnCount).
Attention columnCount was renamed from columeCount (typo fix) in v1.7.1; it is marked with FormerlySerializedAs, so serialized data of old scenes / prefabs migrates automatically.
HorizontalGridInfiniteScrollView
Horizontal grid infinite list (scrolls left and right) with rowCount cells stacked per column.
| Type | public class HorizontalGridInfiniteScrollView : InfiniteScrollView |
| Source | HorizontalGridInfiniteScrollView.cs |
| Member | Description |
|---|---|
public Vector2 spacing | Cell spacing (x = horizontal, y = vertical). |
public int rowCount | Row count (cells stacked per column), default 1 (values less than or equal to 0 are treated as 1). |
Overridden Behaviors
public override void Snap(int index, float duration)
Snap: calculates the horizontal target position from the column the target index belongs to (index / rowCount).