Ejemplo 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);
        }
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);
            }
        }
Ejemplo n.º 3
0
        public static void BuildLevel(LDtkDataProject project, LDtkLevelIdentifier levelToBuild, LDtkProjectAssets assets)
        {
            if (assets == null)
            {
                Debug.LogError("LDtk: ProjectAssets object is null; not building level.");
                return;
            }
            if (levelToBuild == null)
            {
                Debug.LogError("LDtk: LDtkLevelIdentifier object is null; not building level.");
                return;
            }

            if (!LDtkUnityTilesetBuilder.ValidateTilemapPrefabRequirements(assets.TilemapPrefab))
            {
                return;
            }


            bool success = GetProjectLevelByID(project.levels, levelToBuild, out LDtkDataLevel level);

            if (!success)
            {
                return;
            }

            string debugLvlName = $"\"{level.identifier}\"";
            //Debug.Log($"LDtk: Building level: {debugLvlName}");
            Stopwatch levelBuildTimer = Stopwatch.StartNew();

            BuildProcess(project, level, assets);

            levelBuildTimer.Stop();
            double ms = levelBuildTimer.ElapsedMilliseconds;

            Debug.Log($"LDtk: Built level {debugLvlName} in {ms}ms ({ms/1000}s)");

            OnLevelBuilt?.Invoke(level);
        }