Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Unity Tilemap从x和y索引获取矢量3世界位置_C#_Unity3d - Fatal编程技术网

C# Unity Tilemap从x和y索引获取矢量3世界位置

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

我试图理解Tilemaps,特别是我希望能够使用Tilemap的x,y索引获得向量3的位置。我知道你可以从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)");
        }
    }
}
//此代码块是从另一个答案中收集的。
BoundsInt bounds=tilemap.cellBounds;
TileBase[]allTiles=tilemap.GetTilesBlock(边界);
for(int x=0;x
见我上面的评论:

“如何从x,y方向获取平铺的transform.position?” 索引?”


使用此函数从平铺中获取平铺数据:

如果您从TileBase派生了自己的类,请重写此函数并返回TileData: