Dungeon Generator

Presented by IDungeonGenerator interface, this system allows to generate dungeons of needed size and complexity by maens of BSP algorithm.

Dungeon generation

To use it, you can just drag DungeonGenerator prefab onto your game scene and set it up as you want.

DungeonGenerator prefab

Parameters in inspector

Parameters in inspector

Floor Tile Prefabs – list of floor tile prefabs. You can add your own tiles here, they should be gameobjects with width and length equal to 1 unit, height can have any value.

Wall Tile Prefabs – list of wall tile prefabs. You can add your own tiles here, they should be gameobjects with width and length equal to 1 unit, height can have any value.

Enable Walls – if set to true, walls will be generated, otherwise, dungeon will be only with floor tiles.

Dungeon Width – width of dungeon, 50 units by default.

Dungeon Length – length of dungeon, 50 units by default.

Min Room Size – minimal room size in units.

Max Iterations – max number of rooms splitting iterations.

Room Margin – margin between rooms in units.

Corridor Width – typical width of corridor in units.


You can also use its functionality via code. For this, inject IDungeonGenerator interface into your class.

Available methods

List<DungeonRoom> GenerateDungeon(Vector3 pos)

This method generates dungeon with default settings set in DungeonGenerator inspector.


List<DungeonRoom> GenerateDungeon(Vector3 pos, int width, int length)

This method generates dungeon with default settings set in DungeonGenerator inspector, but with custom width and length.


List<DungeonRoom> GenerateDungeon(Vector3 pos, int width, int length, 
    bool enableWalls = true, int minRoomSize = 5, int roomMargin = 2, 
    int maxIterations = 5)

This method generates dungeon with custom settings.

Example:

dungeonGenerator.GenerateDungeon(playerPos, 40, 40, true, 6, 2, 4);

void ClearDungeon()

This method clears current dungeon. Automatically called when new dungeon is being generated.


void GenerateNavMesh()

This method generates NavMesh for current dungeon.

Last updated