Version: 2020.2
public void SetTiles (Vector3Int[] positionArray, TileBase[] tileArray);

参数

positionArray Tilemap 上的瓦片的位置数组。
tileArray 要放置的 Tiles 的数组。

描述

根据给定的瓦片地图中对应单元格的 XYZ 坐标,设置瓦片的数组。

// Fills tilemap area with checkerboard pattern of tileA and tileB
using UnityEngine;
using UnityEngine.Tilemaps;

public class ExampleClass : MonoBehaviour { public TileBase tileA; public TileBase tileB; public Vector2Int size;

void Start() { Vector3Int[] positions = new Vector3Int[size.x * size.y]; TileBase[] tileArray = new TileBase[positions.Length];

for (int index = 0; index < positions.Length; index++) { positions[index] = new Vector3Int(index % size.x, index / size.y, 0); tileArray[index] = index % 2 == 0 ? tileA : tileB; }

Tilemap tilemap = GetComponent<Tilemap>(); tilemap.SetTiles(positions, tileArray); } }