【发布时间】:2018-07-20 03:42:38
【问题描述】:
我正在尝试了解 Tilemap,特别是我希望能够使用 Tilemap 的 x、y 索引来获得 Vector3 位置。我看到您可以从 Tilemap 中获取 TileBase 数组,但其中似乎没有任何实际数据可以提供此信息。
我还看到有一个 TileData 类,但我不确定如何将 TileBase 转换为 TileData 以便从中检索位置。
// This code block was gathered from another answer.
BoundsInt bounds = tilemap.cellBounds;
TileBase[] allTiles = tilemap.GetTilesBlock(bounds);
for (int x = 0; x < bounds.size.x; x++) {
for (int y = 0; y < bounds.size.y; y++) {
TileBase tile = allTiles[x + y * bounds.size.x];
if (tile != null) {
Debug.Log("x:" + x + " y:" + y + " tile:" + tile.name);
// How do I get the transform.position of the tile from
// the x, y indexes?
} else {
Debug.Log("x:" + x + " y:" + y + " tile: (null)");
}
}
}
见我上面的评论:
"我如何从 x, y 获取图块的 transform.position 索引?”
【问题讨论】: