Exemple #1
0
        public void WriteTilemap(Tilemap tilemap)
        {
            var bounds = tilemap.cellBounds;

            // Create filename for this csv file
            var path = BaseOutputPath
                       + BaseFilename
                       + string.Format("{0:yyyy_MM_ddTHH_mm_ss}", DateTime.Now)
                       + $"_{bounds.xMax}x{bounds.yMax}"
                       + BaseFilenameSuffix;

            string line;

            // Write tilemap content into file
            StreamWriter streamWriter = File.CreateText(path);

            // Write tilemap dimensions
            line = string.Format("{0}, {1}", bounds.xMax - bounds.xMin, bounds.yMax - bounds.yMin);
            streamWriter.WriteLine(line);
            streamWriter.Flush();

            // Write column names
            line = string.Format("{0},{1},{2}", "Tile X", "Tile Y", "Tile Type");
            streamWriter.WriteLine(line);
            streamWriter.Flush();

            int        typeId;
            TileBase   tile;
            Vector3Int position = Vector3Int.zero;

            for (int x = bounds.xMin; x < bounds.xMax; x++)
            {
                for (int y = bounds.yMin; y < bounds.yMax; y++)
                {
                    position.x = x;
                    position.y = y;
                    tile       = tilemap.GetTile(position);
                    if (tile != null)
                    {
                        typeId = (int)TilemapHelper.GetTileTypeFromSpriteName(tile.name);
                        line   = string.Format("{0},{1},{2}", x, y, typeId);
                    }
                    else
                    {
                        line = string.Format("{0},{1},{2}", x, y, NullTile);
                    }
                    streamWriter.WriteLine(line);
                    streamWriter.Flush();
                }
            }

            streamWriter.Close();
            streamWriter.Dispose();
        }
Exemple #2
0
        public TileType?Apply(TileBase[] neighbors)
        {
            if (neighbors.Length < 9)
            {
                return(null);
            }
            // Get middle tile
            var tile = neighbors[(int)TilePositions.MIDDLE];

            var tileType = TilemapHelper.GetTileTypeFromSpriteName(tile.name);

            // Check if the tile is already a wall
            if (tileType == TileType.WALL)
            {
                return(null);
            }
            // Check if the tile is not floor
            if (tileType != TileType.ROOM)
            {
                return(null);
            }

            var neighborTypes = new TileType[8];
            int index         = 0;
            int count         = 0;

            foreach (var neighbor in neighbors)
            {
                if (count != (int)TilePositions.MIDDLE)
                {
                    neighborTypes[index] = TilemapHelper.GetTileTypeFromSpriteName(neighbor.name);
                    index++;
                }
                count++;
            }

            if (TilemapHelper.IsNextToType(neighborTypes, TileType.CORRIDOR))
            {
                return(TileType.WALL);
            }

            return(null);
        }
Exemple #3
0
        public TileType?Apply(TileBase[] neighbors)
        {
            if (neighbors.Length < 9)
            {
                return(null);
            }
            // Get middle tile
            var tile = neighbors[(int)TilePositions.MIDDLE];

            // Check if the tile is already a wall
            if (TilemapHelper.GetTileTypeFromSpriteName(tile.name) == TileType.WALL)
            {
                return(null);
            }

            // Get horizontal and vertical adjacent tiles
            var adjacents = new TileBase[4] {
                neighbors[(int)TilePositions.MIDDLE_LEFT],
                neighbors[(int)TilePositions.MIDDLE_RIGHT],
                neighbors[(int)TilePositions.TOP_MIDDLE],
                neighbors[(int)TilePositions.DOWN_MIDDLE]
            };

            int count = 0;

            foreach (var adjacentTile in adjacents)
            {
                if (adjacentTile != null)
                {
                    count += TilemapHelper.GetTileTypeFromSpriteName(adjacentTile.name) == TileType.WALL ?
                             1 : 0;
                }
            }

            if (count >= 2)
            {
                return(TileType.WALL);
            }

            return(null);
        }