Esempio n. 1
0
        private static void BuildIntGridLayer(LDtkDataLayer layer, LDtkIntGridValueAssetCollection intGridValueAssets,
                                              Grid tilemapPrefab)
        {
            if (IsAssetNull(intGridValueAssets))
            {
                return;
            }
            if (IsAssetNull(tilemapPrefab))
            {
                return;
            }

            DecrementLayer();

            Tilemap tilemap = LDtkUnityTilesetBuilder.BuildUnityTileset(layer.__identifier, tilemapPrefab, _layerSortingOrder);

            if (tilemap == null)
            {
                return;
            }

            LDtkBuilderIntGridValue.BuildIntGridValues(layer, intGridValueAssets, tilemap);

            LDtkUnityTilesetBuilder.SetTilesetOpacity(tilemap, layer.__opacity);
        }
Esempio 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);
            }
        }