Runtime API¶
All runtime APIs are in the DungeonMaster namespace.
Generate A Layout In Code¶
using DungeonMaster;
using UnityEngine;
public class RuntimeDungeonExample : MonoBehaviour
{
public Dungeon3DBuilder Builder;
public DungeonThemeProfile Theme;
public void Generate()
{
DungeonGenerationSettings settings = new DungeonGenerationSettings
{
RoomCount = 16,
UseRandomSeed = true,
MinRoomSize = new Vector2Int(2, 2),
MaxRoomSize = new Vector2Int(5, 5),
BranchChance = 0.4f,
LoopChance = 0.15f
};
DungeonLayoutAsset layout = DungeonLayoutGenerator.GenerateAsset(settings);
Builder.Layout = layout;
Builder.Theme = Theme;
Builder.Build();
}
}
Build From An Existing Layout¶
using DungeonMaster;
using UnityEngine;
public class BuildExistingLayout : MonoBehaviour
{
public Dungeon3DBuilder Builder;
public DungeonLayoutAsset Layout;
public DungeonThemeProfile Theme;
private void Start()
{
Builder.Layout = Layout;
Builder.Theme = Theme;
Builder.Build();
}
}
DungeonGenerationSettings¶
| Field | Default | Description |
|---|---|---|
| RoomCount | 12 |
Number of rooms to generate. |
| UseRandomSeed | true |
Uses a changing seed. |
| Seed | 12345 |
Fixed seed when random seed is disabled. |
| MinRoomSize | (2, 2) |
Minimum room size in cells. |
| MaxRoomSize | (4, 5) |
Maximum room size in cells. |
| BranchChance | 0.35 |
Chance to branch from earlier rooms. |
| LoopChance | 0.12 |
Chance to add loop connections. |
| SecretRoomChance | 0.1 |
Chance for eligible rooms to become secret rooms. |
| LockedDoorChance | 0.12 |
Chance for doors to become locked. |
| EmptyRoomDecorationChance | 0.55 |
Chance for normal rooms to receive decorations. |
| RoomSpacing | 1 |
Minimum room spacing. |
| LayoutSpread | 3 |
Extra random placement spread. |
| MaxCorridorLength | 14 |
Maximum preferred corridor length. |
Call Normalize() before using settings if you modify them manually and want values clamped.
DungeonBuildSettings¶
| Field | Default | Description |
|---|---|---|
| CellSize | 4 |
Unity units per grid cell. |
| WallHeight | 3 |
Reserved for wall-height-aware content. |
| ClearPreviousBuild | true |
Clears old generated children before building. |
| PlaceConnectionPrefabAtBothEnds | false |
Places doors/passages at both ends of a connection. |
| RootName | Generated Dungeon |
Name of generated dungeon root object. |
DungeonLayoutAsset¶
DungeonLayoutAsset stores generated room and connection data.
Useful members:
| Member | Description |
|---|---|
Rooms |
Read-only room list. |
Connections |
Read-only connection list. |
Seed |
Seed used to create the layout. |
FindRoom(int roomId) |
Finds a room by id. |
FindConnection(int roomA, int roomB) |
Finds a connection between two rooms. |
SetLayout(...) |
Replaces the layout data. |
Dungeon3DBuilder¶
Attach Dungeon3DBuilder to a scene object when building from code.
Required fields:
LayoutTheme
Optional:
BuildSettings
Build the dungeon with:
GameObject generatedRoot = builder.Build();
If Layout or Theme is missing, the builder logs a warning and returns null.
Validate A Layout¶
using System.Collections.Generic;
using DungeonMaster;
using UnityEngine;
public class LayoutValidationExample : MonoBehaviour
{
public DungeonLayoutAsset Layout;
public void Validate()
{
List<string> issues = DungeonLayoutValidator.Validate(Layout);
foreach (string issue in issues)
{
Debug.LogWarning(issue);
}
}
}
Read Door Metadata¶
using DungeonMaster;
using UnityEngine;
public class DoorReader : MonoBehaviour
{
private void Start()
{
foreach (DungeonDoor door in FindObjectsByType<DungeonDoor>(FindObjectsSortMode.None))
{
if (door.IsLocked)
{
Debug.Log($"Locked door requires key: {door.KeyId}");
}
if (door.IsSecret)
{
Debug.Log("Found a secret door.");
}
}
}
}
Read Content Metadata¶
using DungeonMaster;
using UnityEngine;
public class ContentReader : MonoBehaviour
{
private void Start()
{
foreach (DungeonContentMarkerComponent marker in FindObjectsByType<DungeonContentMarkerComponent>(FindObjectsSortMode.None))
{
Debug.Log($"Room {marker.RoomId} spawned content type {marker.Type}");
}
}
}