public static void BuildTileset(LDtkDataLayer layer, LDtkDataTile[] tiles, LDtkTilesetAssetCollection assets, Tilemap[] tilemaps) { LDtkDefinitionTileset definition = layer.IsAutoTilesLayer ? layer.Definition.AutoTilesetDefinition : layer.Definition.TileLayerDefinition; LDtkTilesetAsset asset = assets.GetAssetByIdentifier(definition.identifier); if (asset == null) { return; } //figure out if we have already built a tile in this position. otherwise, build up to the next tilemap Dictionary <Vector2Int, int> builtTileLayering = new Dictionary <Vector2Int, int>(); foreach (LDtkDataTile tileData in tiles) { Vector2Int px = tileData.px.ToVector2Int(); int tilemapLayer = GetTilemapLayerToBuildOn(builtTileLayering, px, tilemaps.Length - 1); BuildTile(layer, tileData, asset, tilemaps[tilemapLayer]); } }
private static void BuildTilesetLayer(LDtkDataLayer layer, LDtkDataTile[] tiles, LDtkTilesetAssetCollection tilesetAssets, Grid tilemapPrefab) { if (IsAssetNull(tilesetAssets)) { return; } var grouped = tiles.Select(p => p.px.ToVector2Int()).ToLookup(x => x); int maxRepetitions = grouped.Max(x => x.Count()); string objName = layer.__identifier; if (layer.IsIntGridLayer) { objName += "_AutoLayer"; } //this is for the potential of having multiple rules apply to the same tile. make multiple Unity Tilemaps. Tilemap[] tilemaps = new Tilemap[maxRepetitions]; for (int i = 0; i < maxRepetitions; i++) { string name = objName; name += $"_{i}"; Tilemap tilemap = BuildUnityTileset(name, tilemapPrefab); if (tilemap == null) { return; } tilemaps[i] = tilemap; } LDtkBuilderTileset.BuildTileset(layer, tiles, tilesetAssets, tilemaps); }
private static void BuildTilesetLayer(LDtkDataLayer layer, LDtkDataTile[] tiles, LDtkTilesetAssetCollection tilesetAssets, Grid tilemapPrefab) { if (IsAssetNull(tilesetAssets)) { return; } if (IsAssetNull(tilemapPrefab)) { return; } var grouped = tiles.Select(p => p.px.ToVector2Int()).ToLookup(x => x); int maxRepetitions = grouped.Max(x => x.Count()); string gameObjectName = layer.__identifier; if (layer.IsIntGridLayer) { gameObjectName += "_AutoLayer"; } //this is for the potential of having multiple rules apply to the same tile. make multiple Unity Tilemaps. Tilemap[] tilemaps = new Tilemap[maxRepetitions]; for (int i = 0; i < maxRepetitions; i++) { DecrementLayer(); string name = gameObjectName; name += $"_{i}"; Tilemap tilemap = LDtkUnityTilesetBuilder.BuildUnityTileset(name, tilemapPrefab, _layerSortingOrder); if (tilemap == null) { return; } tilemaps[i] = tilemap; } LDtkBuilderTileset.BuildTileset(layer, tiles, tilesetAssets, tilemaps); //set each layer's alpha foreach (Tilemap tilemap in tilemaps) { LDtkUnityTilesetBuilder.SetTilesetOpacity(tilemap, layer.__opacity); } }