Crazy Tractor's Infinite Level System
✨ What You'll Learn:
How to minimize updates by focusing on visible edges
How to use a component to update individual tiles
🧠 Deeper Dive:
When the grid moves, inner tiles are visible. To save on performance, we only update the outer edge tiles (top/bottom rows and left/right columns). We use a TileVisualUpdater
script on each tile to refresh its appearance.
Instead of updating every tile, we update only:
First and last row
First and last tile in each middle row
This drastically improves performance for larger grids and keeps the illusion of an “infinite” grid.
✅ Code Example:
private void UpdateTileEdges()
{
foreach (GameObject tile in TileGrid[0].Tiles)
tile.GetComponent()?.UpdateVisual();
foreach (GameObject tile in TileGrid[TileGrid.Count - 1].Tiles)
tile.GetComponent()?.UpdateVisual();
for (int i = 1; i < TileGrid.Count - 1; i++)
{
tile.GetComponent()?.UpdateVisual();
TileRow row = TileGrid[i];
row.Tiles[0].GetComponent()?.UpdateVisual();
row.Tiles[row.Tiles.Count - 1].GetComponent()?.UpdateVisual();
}
}