Version: 2020.1

Tilemap.GetTilesBlock

切换到手册
public TileBase[] GetTilesBlock (BoundsInt bounds);

参数

bounds 作为检索范围的边界。

返回

TileBase[] 给定边界内的 Tiles 的数组。

描述

使用给定边界检索瓦片数组。

与对每个位置逐一调用 GetTile 相比,这种批量获取瓦片的方式更高效。 边界大小必须与数组大小匹配。例如,边界 1x2x3 需要数组长度 6。

// Retrieves all tiles from an area on the tilemap and prints out the tiles to console
using UnityEngine;
using UnityEngine.Tilemaps;

public class ExampleClass : MonoBehaviour { public BoundsInt area;

void Start() { Tilemap tilemap = GetComponent<Tilemap>(); TileBase[] tileArray = tilemap.GetTilesBlock(area); for (int index = 0; index < tileArray.Length; index++) { print(tileArray[index]); } } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961