Parse json files from the Tiled Map Editor in Unity3d
Using this library is pretty simple:
- Save a .json map file from the Tiled Map Editor and save it in a folder called
Resources. - Call the static function
TiledMap.ReadMap(resourceName)which will return aTiledMapobject. TiledMap.GetTiles()will return all of the tiles- Enumerate the tiles and create instantiate your GameObjects in Unity3d (not part of the demo scene yet)
using UnityEngine;
using TiledJsonUtility;
public class SampleUsage : MonoBehaviour
{
public string TextAssetName;
public void Start()
{
TiledMap map = TiledMap.ReadMap(TextAssetName);
foreach (TiledLayer layer in map.layers)
{
TiledLayerTile[] tiles = layer.GetTiles();
if (tiles != null)
{
foreach (TiledLayerTile tile in tiles)
{
Debug.LogFormat("Tile({0},{1}) = {2} H={3} V={4} D={5}", tile.X, tile.Y, tile.Gid, tile.IsFlippedHorz, tile.IsFlippedVert, tile.IsFlippedDiag);
}
}
}
}
}