Skip to main content

tiled 的坐标 转成 unity的 TileMap坐标

tiled 的坐标 转成 unity的 TileMap坐标

/// <summary>
/// 2. 初始化地图的方块的坐标
/// </summary>
/// <returns></returns>
public void InitMapPosition()
{
int index = 0;
for (var i = mapConfigData.height; i >0; i--)
{
for (var j = 0; j < mapConfigData.width; j ++)
{
//MapPosition.Add(index, new Vector3Int(mapConfigData.height - i, mapConfigData.width - j, 0));
//PositionMap.Add(new Vector3Int(mapConfigData.height - i, mapConfigData.width - j, 0), index);

Vector3Int pos;
int x = (mapConfigData.height - i) / 2 ;

if (i % 2 == 0)
{
pos = new Vector3Int(i/2 + j, mapConfigData.width - j - x , 0);
}
else
{
pos = new Vector3Int(i/2 + j + 1, mapConfigData.width - j -1 - x, 0);
}
//Debug.Log(pos + " ==== " + x);
MapPosition.Add(index, pos);
PositionMap.Add(pos, index);

index++;
}
}
}