Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
            }
        }