SetTilesBlock
Fills an area with array of Tile s.
Read time 2 minutesLast updated 6 days ago
Definition
- Type: Method
- Namespace: UnityEngine.Tilemaps
- Assembly: UnityEngine.TilemapModule
SetTilesBlock(BoundsInt, TileBase[])
Fills an area with array of Tiles.
public void SetTilesBlock(BoundsInt position, TileBase[] tileArray)
Parameters
Remarks
This method is a faster way to set multiple tiles in an area than calling for each tile. The bounds size must match the array size. For example bounds of 1x2x3 needs an array length of 6.
SetTileRefer to Scriptable Tiles and Tilemap for more information.
Examples
// Fill area on Tilemap with checkerboard pattern of tileA and tileBusing UnityEngine;using UnityEngine.Tilemaps;public class ExampleClass : MonoBehaviour{ public TileBase tileA; public TileBase tileB; public BoundsInt area; void Start() { TileBase[] tileArray = new TileBase[area.size.x * area.size.y * area.size.z]; for (int index = 0; index < tileArray.Length; index++) { tileArray[index] = index % 2 == 0 ? tileA : tileB; } Tilemap tilemap = GetComponent<Tilemap>(); tilemap.SetTilesBlock(area, tileArray); }}
SetTilesBlock(BoundsInt, TileArray)
Fills an area with an array of Tiles.
public void SetTilesBlock(BoundsInt position, Tilemap.TileArray tileArray)
Parameters
Remarks
This method is a faster way to set multiple tiles in an area than calling for each tile. The bounds size must match the array size. For example bounds of 1x2x3 needs an array length of 6.
SetTileExamples
// Fill area on Tilemap with checkerboard pattern of tileA and tileBusing UnityEngine;using UnityEngine.Tilemaps;using Unity.Collections;public class ExampleClass_Native : MonoBehaviour{ public TileBase tileA; public TileBase tileB; public BoundsInt area; void Start() { Tilemap.TileArray tileArray = new Tilemap.TileArray(area.size.x * area.size.y * area.size.z, Allocator.Temp); for (int index = 0; index < tileArray.Length; index++) { tileArray[index] = index % 2 == 0 ? tileA : tileB; } Tilemap tilemap = GetComponent<Tilemap>(); tilemap.SetTilesBlock(area, tileArray); }}