Kryat Docs Image
Tile Grid

Methods

Cells Modification

void AddCell(Vector3Int coords, TileLayer layer)

  • Description: Adds a tile cell at the specified coordinates using the specified layer. If no layer is provided, defaults to the first tile layer.

  • Parameters:

  - Vector3Int coords: Coordinates for placing the cell.

  - TileLayer layer: The layer to which the cell belongs.

  • Usage:
    TileLayer layer = tileGrid.GetTileLayer(1);
 
    tileGrid.AddCell(new Vector3Int(5, 5, 0), layer);

void ModifyCell(Vector3Int coords, TileLayer layer)

  • Description: Modifies an existing tile cell at the specified coordinates by applying the given layer. If null, the cell is removed.

  • Parameters:

  - Vector3Int coords: Coordinates of the cell to modify.

  - TileLayer layer: The new layer for the cell.

  • Usage:
tileGrid.ModifyCell(new Vector3Int(3, 3, 0), null); // Remove cell

void RemoveCell(Vector3Int coords)

  • Description: Removes the tile cell at the specified coordinates.

  • Parameters:

  - Vector3Int coords: Coordinates of the cell to remove.

  • Usage:
tileGrid.RemoveCell(new Vector3Int(2, 2, 0));

Utils

Tile GetTileAtCell(Vector3Int coords)

  • Description: Retrieves the tile at the specified coordinates.

  • Parameters:

  - Vector3Int coords: Coordinates of the cell.

  • Returns: Tile at the specified location, or null if no tile exists.

  • Usage:

Tile tile = tileGrid.GetTileAtCell(new Vector3Int(0, 0, 0));

TileLayer GetTileLayerAtCell(Vector3Int coords)

  • Description: Retrieves the tile layer at the specified coordinates.

  • Parameters:

  - Vector3Int coords: Coordinates of the cell.

  • Returns: TileLayer of the cell, or null if no layer is set.

  • Usage:

TileLayer layer = tileGrid.GetTileLayerAtCell(new Vector3Int(0, 0, 0));

int GetTileLayerIndex(TileLayer layer)

  • Description: Retrieves the index of the specified tile layer.

  • Parameters:

  - TileLayer layer: The tile layer whose index is required.

  • Returns: Integer index of the layer.

  • Usage:

int index = tileGrid.GetTileLayerIndex(someLayer);

TileLayer GetTileLayer(int index)

  • Description: Retrieves the tile layer by its index.

  • Parameters:

  - int index: Index of the tile layer.

  • Returns: TileLayer at the specified index.

  • Usage:

TileLayer layer = tileGrid.GetTileLayer(0);

Baking

void Bake()

  • Description: Initializes the grid and pre-generates cells within a specified size range.

  • Usage:

tileGrid.Bake();

void ShowBakedTilemaps()

  • Description: Displays all baked tilemaps on the screen.

void HideBakedTilemaps()

  • Description: Hides all baked tilemaps.

void ClearBakedTilemaps()

  • Description: Clears all baked tilemaps, removing them from the display and memory.

Configuration and Serialized Fields

  • placeholderTilemap (Tilemap): Reference to the placeholder tilemap used for layer management.

  • displayTileLayer (GameObject): Prefab for display tile layers.

  • tileLayers (TileLayer[]): Array of tile layers available for display.

  • bakeSize (int): Specifies the size range for the Bake() function, defaulting to 30.

Usage Examples

// Initialize and bake the tile grid
 
tileGrid.Bake();
 
  
 
// Adding a tile to a specific layer
 
Vector3Int position = new Vector3Int(1, 1, 0);
 
TileLayer groundLayer = tileGrid.GetTileLayer(0);
 
tileGrid.AddCell(position, groundLayer);
 
  
 
// Retrieving and modifying a tile
 
TileLayer tileLayer = tileGrid.GetTileLayerAtCell(position);
 
tileGrid.ModifyCell(position, tileLayer);
 
  
 
// Display baked tiles
 
tileGrid.ShowBakedTilemaps();

On this page