InfiniteCell
Coding Style wiki
InfiniteCell is the base class of cells (MonoBehaviour), attached to the root node of the cell prefab. Cells are recycled by the object pool — implement your display logic by overriding the lifecycle methods, while the data required for rendering is carried by InfiniteCellData.
| Namespace | OxGKit.InfiniteScrollView |
| Type | public class InfiniteCell : MonoBehaviour |
| Source | InfiniteCell.cs |
using OxGKit.InfiniteScrollView;
Reminder Cell script and prefab templates can be created quickly via Right-Click Create/OxGKit/Infinite ScrollView/Template Infinite Cell.cs (Script) and Template Infinite Cell (RectTransform Prefab).
Quick Start
using Cysharp.Threading.Tasks;
using OxGKit.InfiniteScrollView;
using UnityEngine.UI;
public class ItemCell : InfiniteCell
{
public Text titleTxt;
public Button button;
public override async UniTask OnCreate(object args)
{
// One-time initialization on creation (args forwarded from InitializePool(args))
this.button.onClick.AddListener(this.OnClick);
}
public override void OnRefresh()
{
// Cells are pooled and recycled — rendering must be fully driven by cellData
string text = (string)this.cellData.data;
this.titleTxt.text = $"[{this.cellData.index}] {text}";
}
public override void OnRecycle()
{
// Cleanup when recycled back into the pool
}
public override void OnSnap()
{
// Presentation when becoming the snap target (e.g. highlight)
}
public override void OnClick()
{
// Triggers the scroll view's onCellSelected event
base.OnClick();
}
}
General Rules
Lifecycle
| Method | When |
|---|---|
| OnCreate | When InitializePool instantiates the cell (once, awaited). |
| OnRefresh | When cellData is assigned (the cell enters the visible range and gets placed, or the data refreshes). |
| OnRecycle | When the cell is recycled back into the pool (the GameObject is already deactivated). |
| OnSnap | When a Snap finishes and this cell is the target. |
| OnClick | On click (wire the Button event to this method yourself). |
Important Cells are pooled and recycled — the same cell instance displays different data entries in turn, so OnRefresh must redraw fully driven by cellData; never store per-item state on the cell itself (store it in the data object).
Attention Insert / Remove shift the data indexes — read this.cellData.index on demand inside the cell instead of caching index values.
Members
| Member | Description |
|---|---|
public RectTransform rectTransform | The cell's RectTransform (cached automatically). |
public InfiniteCellData cellData | The currently bound data; assigning it (set) automatically triggers OnRefresh. |
Methods
Methods Overview
| Method | Description |
|---|---|
| OnCreate | One-time initialization on creation. |
| OnRefresh | Redraws the display from the data. |
| OnRecycle | Cleanup on recycling. |
| OnSnap | When becoming the snap target. |
| OnClick | Click event (triggers selection). |
| InvokeSelected | (protected) Actively triggers the selection event. |
OnCreate
public virtual async UniTask OnCreate(object args)
awaited once when InitializePool instantiates the cell; args is the custom argument forwarded from InitializePool(args) — suited to one-time setup such as component initialization.
OnRefresh
public virtual void OnRefresh()
Called automatically when cellData is assigned — triggered when the cell is placed for display (enters the visible range); redraw the display content from cellData here.
OnRecycle
public virtual void OnRecycle()
Called when the cell is recycled back into the pool (the GameObject is already deactivated at this point); perform cleanup here (e.g. stop animations, release temporary states).
OnSnap
public virtual void OnSnap()
Called when a Snap finishes and this cell is the target index (suited to tab switching, selection presentation, etc.).
OnClick
public virtual void OnClick()
Click event entry — the default implementation calls InvokeSelected to trigger the scroll view's onCellSelected event; wire the cell's Button event to this method yourself (remember to call base.OnClick() when overriding).
InvokeSelected
protected void InvokeSelected()
Actively triggers the selection event (notifies the scroll view's onCellSelected); call it directly for custom click flows that do not go through OnClick.
InfiniteCellData
The data carrier of a cell, determining the cell size and the rendering data; separated from the cell (view), held by the scroll view, and bound to a cell when it is placed for display.
| Type | public class InfiniteCellData : IDisposable |
| Source | InfiniteCellData.cs |
| Member | Description |
|---|---|
public int index { get; internal set; } | The data index (maintained automatically by the scroll view, updated after Insert / Remove). |
public Vector2 cellSize | The cell size (x = width, y = height): vertical lists use y, horizontal lists use x, grids use both. |
public object data | The custom data required to render the cell. |
Constructors
public InfiniteCellData()
public InfiniteCellData(Vector2 cellSize)
public InfiniteCellData(Vector2 cellSize, object data)
Methods
public void Dispose()
Releases the data reference (data = null); called automatically by the scroll view's Remove / Clear.
Dynamic Size Example (Chat Room)
// Measure the text height with a measuring Text first, then create data with a dynamic height
this.heightInstrument.text = message;
float height = this.heightInstrument.preferredHeight;
this.chatScrollView.Add(new InfiniteCellData(new Vector2(0f, height), new ChatData(user, message)));
this.chatScrollView.Refresh();
this.chatScrollView.SnapLast(0.1f);
Attention cellSize must be decided before adding to the list; to change a size later, update the entry's cellSize and run a full Refresh.