Pooled Grid Layout v1.0

 

The following tutorial will go through creating a performant scrollable grid of numbers.

Check Example scenes for full code and watch the full process in video.

 

PooledCell

Base class for cells that appear in Pooled Grid. Creating your custom cell class, inherit from PooledCell.

Creating custom cell script

pooled_cell_code

 

Creating cell prefab

Now we can create cell prefab that then will be used by Pooled Grid Script to instantiate actual cells.

pooled_cell_scene

 

PooledGridLayoutScript<TCell>

This is a generic class that you need to inherit to create your custom Pooled Grid. Assuming that you already created custom PooledCell class, let's create custom Pooled Grid Script:

pooled_grid_code

Here we actually just giving a name to a generic class with our custom cell.

This script we then can then attach to a ScrollRect in the scene and choose cell prefab that we created earlier:

pooled_grid_scene

 

IPooledGridLayoutDataSource

Now the only code that is missing is our custom data source.

Pooled Grid Layout Script gets data from the object that implements IPooledGridLayoutDataSource interface. Through implementing this interface you feed data to your Pooled Grid.

 

Creating custom data source for Pooled Grid

Any script that implements IPooledGridLayoutDataSource can be a data source for our Pooled Grid.

Let's just create a MonoBehaviour script that will be attached to some gameobject in scene:

data_source_code

Script contains a link to Pooled Grid that we will use to set grid's data source to this script.

First we will initialize data that we want to display in out grid:

data_source_data_init

Here we also set DataSource link and reload the grid to query this script for data through IPooledGridLayoutDataSource interface.

Lets implement this interface:

data_source_code_interface

 

Now all we need to do is create a game object in scene to hold our Data Source script and attach PooledGrid (that sits on a ScrollRect) to it:

data_source_scene

 

Click Play and you should see a fast scrolling pooled grid:

 

play