ManiaMap.Unity
Procedural generation of metroidvania style maps for Unity.
RoomDatabase Class Reference

A database of room prefabs. More...

Inheritance diagram for RoomDatabase:

Public Member Functions

RoomComponent GetRoomPrefab (int id)
 Returns the room prefab with the specified template ID. More...
 
RoomComponent GetRoomPrefab (Uid id, LayoutPack layoutPack)
 Returns the room prefab with the specified room ID. More...
 
IReadOnlyDictionary< int, RoomComponentGetRoomsByTemplateId ()
 Returns the dictionary of rooms by room template ID. More...
 
List< RoomComponentInstantiateAllRooms (LayoutPack layoutPack, Transform parent=null)
 Instantiates all rooms in the layout and returns a list of them. More...
 
RoomComponent InstantiateRoom (Uid id, LayoutPack layoutPack, Transform parent=null, bool assignLayoutPosition=false)
 Instantiates the room with the specified ID. More...
 
List< RoomComponentInstantiateRooms (LayoutPack layoutPack, int? z=null, Transform parent=null)
 Instantiates the rooms in a layer of a layout and returns a list of them. More...
 
void MarkDirty ()
 Sets the object as dirty. More...
 

Properties

bool IsDirty = true [getprivate set]
 If true, the database is dirty and requires population. More...
 
List< RoomComponentRooms [getset]
 A list of room prefabs. More...
 
Dictionary< int, RoomComponentRoomsByTemplateId = new Dictionary<int, RoomComponent>() [get]
 A dictionary of room prefabs by room template ID. More...
 

Private Member Functions

void Awake ()
 
void OnValidate ()
 
void PopulateIfDirty ()
 If the object is dirty, populates the room dictionary. More...
 
void PopulateRoomsByTemplateId ()
 Populates the room dictionary. More...
 

Private Attributes

List< RoomComponent_rooms = new List<RoomComponent>()
 

Detailed Description

A database of room prefabs.

Definition at line 13 of file RoomDatabase.cs.

Member Function Documentation

◆ Awake()

void Awake ( )
private

Definition at line 32 of file RoomDatabase.cs.

◆ GetRoomPrefab() [1/2]

RoomComponent GetRoomPrefab ( int  id)

Returns the room prefab with the specified template ID.

Parameters
idThe template ID.

Definition at line 94 of file RoomDatabase.cs.

◆ GetRoomPrefab() [2/2]

RoomComponent GetRoomPrefab ( Uid  id,
LayoutPack  layoutPack 
)

Returns the room prefab with the specified room ID.

Parameters
idThe room ID.
layoutPackThe layout pack.

Definition at line 105 of file RoomDatabase.cs.

◆ GetRoomsByTemplateId()

IReadOnlyDictionary< int, RoomComponent > GetRoomsByTemplateId ( )

Returns the dictionary of rooms by room template ID.

Definition at line 45 of file RoomDatabase.cs.

◆ InstantiateAllRooms()

List< RoomComponent > InstantiateAllRooms ( LayoutPack  layoutPack,
Transform  parent = null 
)

Instantiates all rooms in the layout and returns a list of them.

Parameters
layoutPackThe layout pack.
parentThe parent transform.

Definition at line 116 of file RoomDatabase.cs.

◆ InstantiateRoom()

RoomComponent InstantiateRoom ( Uid  id,
LayoutPack  layoutPack,
Transform  parent = null,
bool  assignLayoutPosition = false 
)

Instantiates the room with the specified ID.

Parameters
idThe room ID.
layoutPackThe layout pack.
parentThe parent transform.
assignLayoutPositionIf true, moves the instantiated room's local position to its position in the layout.

Definition at line 161 of file RoomDatabase.cs.

◆ InstantiateRooms()

List< RoomComponent > InstantiateRooms ( LayoutPack  layoutPack,
int?  z = null,
Transform  parent = null 
)

Instantiates the rooms in a layer of a layout and returns a list of them.

Parameters
layoutPackThe layout pack.
zThe layer (z) coordinate of the rooms to instantiate. If null, the first layer coordinate found will be used.
parentThe parent transform.

Definition at line 136 of file RoomDatabase.cs.

◆ MarkDirty()

void MarkDirty ( )

Sets the object as dirty.

Definition at line 54 of file RoomDatabase.cs.

◆ OnValidate()

void OnValidate ( )
private

Definition at line 37 of file RoomDatabase.cs.

◆ PopulateIfDirty()

void PopulateIfDirty ( )
private

If the object is dirty, populates the room dictionary.

Definition at line 62 of file RoomDatabase.cs.

◆ PopulateRoomsByTemplateId()

void PopulateRoomsByTemplateId ( )
private

Populates the room dictionary.

Exceptions
DuplicateIdExceptionRaised if two unique rooms have the same template ID.

Definition at line 75 of file RoomDatabase.cs.

Member Data Documentation

◆ _rooms

List<RoomComponent> _rooms = new List<RoomComponent>()
private

Definition at line 16 of file RoomDatabase.cs.

Property Documentation

◆ IsDirty

bool IsDirty = true
getprivate set

If true, the database is dirty and requires population.

Definition at line 30 of file RoomDatabase.cs.

◆ Rooms

List<RoomComponent> Rooms
getset

A list of room prefabs.

Definition at line 20 of file RoomDatabase.cs.

◆ RoomsByTemplateId

Dictionary<int, RoomComponent> RoomsByTemplateId = new Dictionary<int, RoomComponent>()
getprivate

A dictionary of room prefabs by room template ID.

Definition at line 25 of file RoomDatabase.cs.


The documentation for this class was generated from the following file: