Version: 2021.2

Tilemap.GetTilesRangeCount

切换到手册
public int GetTilesRangeCount (Vector3Int startPosition, Vector3Int endPosition);

参数

startPosition The starting position of the range to retrieve Tiles from.
endPosition The ending position of the range to retrieve Tiles from.

返回

int Returns the number of Tiles within the given range.

描述

Retrieves the number of Tiles within the given range.

The range is inclusive of the endPosition parameter.

// Retrieves all tiles with a range on the tilemap and prints out the positions and tiles to console
using UnityEngine;
using UnityEngine.Tilemaps;

public class ExampleClass : MonoBehaviour { void Start() { Tilemap tilemap = GetComponent<Tilemap>(); var count = tilemap.GetTilesRangeCount(new Vector3Int(0, 0, 0), new Vector3Int(10, 0, 0)); Vector3Int[] positions = new Vector3Int[count]; TileBase[] tiles = new TileBase[count]; tilemap.GetTilesRangeNonAlloc(new Vector3Int(0, 0, 0), new Vector3Int(10, 0, 0), positions, tiles); for (int index = 0; index < count; index++) { print(positions[index]); print(tiles[index]); } } }