C# Unity Tilemap从x和y索引获取矢量3世界位置
我试图理解Tilemaps,特别是我希望能够使用Tilemap的x,y索引获得向量3的位置。我知道你可以从Tilemap中得到一个TileBase数组,但是里面似乎没有任何实际的数据提供这些信息 我还看到有一个TileData类,但我不确定如何将TileBase转换为TileData,以便从中检索位置C# Unity Tilemap从x和y索引获取矢量3世界位置,c#,unity3d,C#,Unity3d,我试图理解Tilemaps,特别是我希望能够使用Tilemap的x,y索引获得向量3的位置。我知道你可以从Tilemap中得到一个TileBase数组,但是里面似乎没有任何实际的数据提供这些信息 我还看到有一个TileData类,但我不确定如何将TileBase转换为TileData,以便从中检索位置 // This code block was gathered from another answer. BoundsInt bounds = tilemap.cellBounds; TileB
// 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)");
}
}
}
//此代码块是从另一个答案中收集的。
BoundsInt bounds=tilemap.cellBounds;
TileBase[]allTiles=tilemap.GetTilesBlock(边界);
for(int x=0;x
见我上面的评论:
“如何从x,y方向获取平铺的transform.position?”
索引?”
使用此函数从平铺中获取平铺数据: 如果您从TileBase派生了自己的类,请重写此函数并返回TileData: