Beispiel #1
0
 // Awake
 private void Awake()
 {
     if (TileHandler.instance == null)
     {
         TileHandler.instance = this;
     }
     else
     {
         tileSets = TileHandler.instance.tileSets;
     }
 }
Beispiel #2
0
        // Debug: Visualize Dungeon Structure with Tiles (Proper Rooms)
        private void VisualizeRooms(Dungeon dungeon)
        {
            // Return if Argument is Null
            if (dungeon == null)
            {
                return;
            }
            List <Room> rooms = dungeon.GetRooms();

            // Search TileSet
            DungeonPreset dungeonPreset = dungeon.GetDungeonPreset();

            string theme = dungeonPreset.Theme;

            List <TileSet> tileSets = TileHandler.GetTileSets(theme);

            TileSet tileSet = tileSets.Count > 0 ? tileSets[0] : null;

            if (tileSet == null)
            {
                Debug.LogError("Could Not Find TileSet Theme " + theme);
                return;
            }

            // Iterate all Rooms and Spawn Objects
            foreach (Room room in rooms)
            {
                // Create each Tile (Wall or Ground) of Room
                Coordinates coordinates = room.GetCoordinates();

                for (int y = 0; y < Room.HEIGHT; y++)
                {
                    for (int x = 0; x < Room.WIDTH; x++)
                    {
                        Vector3Int position = new Vector3Int(
                            (coordinates.X * (Room.WIDTH + Room.PADDING)) + x,
                            (coordinates.Y * (Room.HEIGHT + Room.PADDING)) + y,
                            0
                            );

                        bool isWall = x == 0 || y == 0 || x == Room.WIDTH - 1 || y == Room.HEIGHT - 1;

                        tilemap.SetTile(position, isWall ? tileSet.GetRandomTile(TileType.WALL) : tileSet.GetRandomTile(TileType.GROUND));
                    }
                }

                // Check and Create Doors
                Dictionary <Direction, Door> doors = room.GetDoors();

                foreach (Direction direction in doors.Keys)
                {
                    int x = 0;
                    int y = 0;

                    if (Direction.NORTH.Equals(direction))
                    {
                        x = Room.WIDTH / 2;
                        y = 0;
                    }

                    if (Direction.EAST.Equals(direction))
                    {
                        x = Room.WIDTH - 1;
                        y = Room.HEIGHT / 2;
                    }

                    if (Direction.SOUTH.Equals(direction))
                    {
                        x = Room.WIDTH / 2;
                        y = Room.HEIGHT - 1;
                    }

                    if (Direction.WEST.Equals(direction))
                    {
                        x = 0;
                        y = Room.HEIGHT / 2;
                    }

                    Vector3Int position = new Vector3Int(
                        (coordinates.X * (Room.WIDTH + Room.PADDING)) + x,
                        (coordinates.Y * (Room.HEIGHT + Room.PADDING)) + y,
                        0
                        );

                    tilemap.SetTile(position, tileSet.GetRandomTile(TileType.DOOR));

                    position = new Vector3Int(position.x + (direction.Y != 0 ? -1 : 0), position.y + (direction.X != 0 ? -1 : 0), position.z);

                    tilemap.SetTile(position, tileSet.GetRandomTile(TileType.DOOR));
                }
            }
        }