![]() |
ManiaMap.Unity
Procedural generation of metroidvania style maps for Unity.
|
A component for creating a room. More...
Public Member Functions | |
int | AutoAssign () |
Runs auto assign on the room's cell children. Returns the number of children. More... | |
Vector3 | CellCenterGlobalPosition (int row, int column) |
Returns the cell center for the specified index in global coordinates. More... | |
Vector3 | CellCenterGridPosition (int row, int column) |
Returns the cell center for the specified index in grid coordinates. More... | |
Vector3 | CellCenterLocalPosition (int row, int column) |
Returns the cell center for the specified index in local coordinates. More... | |
bool | CellIndexExists (int row, int column) |
Returns true if the cell index exists. More... | |
bool | CellIndexRangeExists (Vector2Int startIndex, Vector2Int endIndex) |
Returns true if both cell indexes exist. More... | |
Vector3 | CenterGlobalPosition () |
Returns the center of the cell grid in global coordinates. More... | |
Vector3 | CenterGridPosition () |
Returns the center of the cell grid in grid coordinates. More... | |
Vector3 | CenterLocalPosition () |
Returns the center of the cell grid in local coordinates. More... | |
Vector2Int | FindClosestActiveCellIndex (Vector3 position) |
Returns the closest active cell index for the specified global position. More... | |
DoorDirection | FindClosestDoorDirection (int row, int column, Vector3 position) |
Returns the closest door direction based on the specified global position. More... | |
bool | GetCellActivity (int row, int column) |
Returns the cell activity for the specified index. More... | |
Quaternion | GetCellViewDirection () |
Returns the quaternion angle perpendicular to the cell plane. More... | |
RoomTemplate | GetMMRoomTemplate (int id, string name) |
Returns the Mania Map room template used by the procedural generator. More... | |
Vector2Int | GlobalPositionToCellIndex (Vector3 position) |
Converts the specified global position to the containing cell index. If the cell index does not exist, returns (-1, -1). More... | |
Vector3 | GlobalToGridPosition (Vector3 globalPosition) |
Converts the specified global position to grid coordinates. More... | |
Vector2Int | GridPositionToCellIndex (Vector3 position) |
Converts the specified grid position to the containing cell index. If the cell index does not exist, returns (-1, -1). More... | |
Vector3 | GridToLocalPosition (Vector3 gridPosition) |
Converts the specified grid coordinate to local coordinates. More... | |
bool | Initialize (LayoutPack layoutPack, Room roomLayout, RoomState roomState, int cellLayer, LayerMask triggeringLayers, bool assignLayoutPosition) |
Initializes the room. Returns false if the room has already been initialized. More... | |
Vector3 | LocalCellSize () |
Returns the cell size in local coordinates. More... | |
Vector2Int | LocalPositionToCellIndex (Vector3 position) |
Converts the specified local position to the containing cell index. If the cell index does not exist, returns (-1, -1). More... | |
Vector3 | LocalToGridPosition (Vector3 localPosition) |
Converts the specified local coordinate to grid coordinates. More... | |
bool | SetCellActivities (Vector2Int startIndex, Vector2Int endIndex, CellActivity activity) |
Sets the cell activities for the specified index range. No action is taken if one of the indexes is out of range. Returns false if no action is taken. More... | |
void | SetCellActivity (int row, int column, bool activity) |
Sets the cell activity for the specified index. More... | |
void | SetCellActivity (int row, int column, CellActivity activity) |
Sets the cell activity for the specified index. More... | |
void | SizeActiveCells () |
Sizes the active cells list to match the room size. More... | |
void | ValidateRoomFlags () |
Validates that the room flag ID's are unique. More... | |
Static Public Member Functions | |
static RoomComponent | InstantiateRoom (GameObject prefab, Transform parent, LayoutPack layoutPack, Room roomLayout, RoomState roomState, int cellLayer, LayerMask triggeringLayers, bool assignLayoutPosition) |
Instantiates and initializes a room and returns it. More... | |
static RoomComponent | InstantiateRoom (Uid id, LayoutPack layoutPack, GameObject prefab, Transform parent=null, bool assignLayoutPosition=false) |
Instantiates and initializes a room and returns it. More... | |
static AsyncOperationHandle< GameObject > | InstantiateRoomAsync (AssetReferenceGameObject prefab, Transform parent, LayoutPack layoutPack, Room roomLayout, RoomState roomState, int cellLayer, LayerMask triggeringLayers, bool assignLayoutPosition) |
Instantiates and initializes a room asynchronously. Returns the operation handle. More... | |
static AsyncOperationHandle< GameObject > | InstantiateRoomAsync (Uid id, LayoutPack layoutPack, AssetReferenceGameObject prefab, Transform parent=null, bool assignLayoutPosition=false) |
Instantiates and initializes a room asynchronously. Returns the operation handle. More... | |
Properties | |
List< ActiveCellsRow > | ActiveCells [getset] |
A list of active cell rows. More... | |
Vector3 | CellSize [getset] |
The size of each cell within the grid coordinate system. More... | |
int | Columns [getset] |
The column index. More... | |
bool | IsInitialized [getprivate set] |
True if the room has been initialized. More... | |
LayoutPack | LayoutPack [getprivate set] |
The layout pack. More... | |
string | Name [getset] |
The room name. More... | |
CellAreaTriggerEvent | OnCellAreaEntered [getset] |
The event invoked when a room cell has been entered. Message includes the enterered cell and the colliding GameObject. More... | |
CellAreaTriggerEvent | OnCellAreaExited [getset] |
The event invoked when a room cell has been exited. Message includes the exited cell and the colliding GameObject. More... | |
UnityEvent | OnInitialize [getset] |
An event invoked when the room is initialized. More... | |
UnityEvent | OnInitialized [getset] |
The event invoked after the room has completed initialization. More... | |
Room | RoomLayout [getprivate set] |
The room data. More... | |
RoomState | RoomState [getprivate set] |
The room state. More... | |
RoomTemplateResource | RoomTemplate [getset] |
The room template. More... | |
RoomType | RoomType [getset] |
The room type. More... | |
int | Rows [getset] |
The row index. More... | |
Vector2Int | Size [getset] |
The size of the room grid in rows (x) and columns (y). More... | |
Private Member Functions | |
void | AddMMDoors (Array2D< Cell > cells) |
Adds the Mania Map doors to the cells array. More... | |
void | AddMMFeatures (Array2D< Cell > cells) |
Adds the cell features to the cells array. More... | |
void | CreateCellAreas (int cellLayer, LayerMask triggeringLayers) |
Creates the cell area triggers as children of the room. More... | |
void | DrawCells (Color fillColor, Color lineColor, bool activity) |
Draws the cell cube gizmos for the specified cell activity. More... | |
Array2D< Cell > | GetMMCells () |
Returns the Mania Map cells used by the procedural generator. More... | |
Dictionary< int, CollectableSpot > | GetMMCollectableSpots () |
Returns the Mania Map collectable spots by ID. More... | |
void | MoveToLayoutPosition () |
Sets the room's local position to its position in the layout. More... | |
void | OnDrawGizmos () |
void | OnValidate () |
void | SetSizeField (ref Vector2Int field, Vector2Int value) |
Private Attributes | |
List< ActiveCellsRow > | _activeCells = new List<ActiveCellsRow>() |
Vector3 | _cellSize = new Vector3(1, 1, 0.001f) |
string | _name = "<None>" |
CellAreaTriggerEvent | _onCellAreaEntered = new CellAreaTriggerEvent() |
CellAreaTriggerEvent | _onCellAreaExited = new CellAreaTriggerEvent() |
UnityEvent | _onInitialize = new UnityEvent() |
UnityEvent | _onInitialized = new UnityEvent() |
RoomTemplateResource | _roomTemplate |
RoomType | _roomType |
Vector2Int | _size = Vector2Int.one |
A component for creating a room.
The room contains methods for various coordinate systems:
Cell related calculations are generally performed within Grid Coordinate space since that is consistent between room types.
Definition at line 23 of file RoomComponent.cs.
|
private |
Adds the Mania Map doors to the cells array.
cells | The cells array. |
Definition at line 680 of file RoomComponent.cs.
|
private |
Adds the cell features to the cells array.
cells | The cells array. |
Definition at line 693 of file RoomComponent.cs.
int AutoAssign | ( | ) |
Runs auto assign on the room's cell children. Returns the number of children.
Definition at line 453 of file RoomComponent.cs.
Vector3 CellCenterGlobalPosition | ( | int | row, |
int | column | ||
) |
Returns the cell center for the specified index in global coordinates.
row | The row index. |
column | The column index. |
Definition at line 589 of file RoomComponent.cs.
Vector3 CellCenterGridPosition | ( | int | row, |
int | column | ||
) |
Returns the cell center for the specified index in grid coordinates.
row | The row index. |
column | The column index. |
Definition at line 579 of file RoomComponent.cs.
Vector3 CellCenterLocalPosition | ( | int | row, |
int | column | ||
) |
Returns the cell center for the specified index in local coordinates.
row | The row index. |
column | The column index. |
Definition at line 599 of file RoomComponent.cs.
bool CellIndexExists | ( | int | row, |
int | column | ||
) |
Returns true if the cell index exists.
row | The row index. |
column | The column index. |
Definition at line 435 of file RoomComponent.cs.
bool CellIndexRangeExists | ( | Vector2Int | startIndex, |
Vector2Int | endIndex | ||
) |
Returns true if both cell indexes exist.
startIndex | The first index. |
endIndex | The second index. |
Definition at line 445 of file RoomComponent.cs.
Vector3 CenterGlobalPosition | ( | ) |
Returns the center of the cell grid in global coordinates.
Definition at line 503 of file RoomComponent.cs.
Vector3 CenterGridPosition | ( | ) |
Returns the center of the cell grid in grid coordinates.
Definition at line 487 of file RoomComponent.cs.
Vector3 CenterLocalPosition | ( | ) |
Returns the center of the cell grid in local coordinates.
Definition at line 495 of file RoomComponent.cs.
|
private |
Creates the cell area triggers as children of the room.
cellLayer | The physics layer assigned to cell triggers. |
triggeringLayers | The physics layers that trigger the room cell triggers. |
Definition at line 300 of file RoomComponent.cs.
|
private |
Draws the cell cube gizmos for the specified cell activity.
fillColor | The gizmo fill color. |
lineColor | The gizmo line color. |
activity | The activity of the cells to draw. |
Definition at line 153 of file RoomComponent.cs.
Vector2Int FindClosestActiveCellIndex | ( | Vector3 | position | ) |
Returns the closest active cell index for the specified global position.
position | The global position. |
Definition at line 737 of file RoomComponent.cs.
DoorDirection FindClosestDoorDirection | ( | int | row, |
int | column, | ||
Vector3 | position | ||
) |
Returns the closest door direction based on the specified global position.
row | The cell row index. |
column | The cell column index. |
position | The global position. |
Definition at line 775 of file RoomComponent.cs.
bool GetCellActivity | ( | int | row, |
int | column | ||
) |
Returns the cell activity for the specified index.
row | The row index. |
column | The column index. |
System.IndexOutOfRangeException | Raised if the specified index is out of range. |
Definition at line 422 of file RoomComponent.cs.
Quaternion GetCellViewDirection | ( | ) |
Returns the quaternion angle perpendicular to the cell plane.
System.ArgumentException | Raised if the room type is not handled. |
Definition at line 470 of file RoomComponent.cs.
|
private |
Returns the Mania Map cells used by the procedural generator.
Definition at line 660 of file RoomComponent.cs.
|
private |
Returns the Mania Map collectable spots by ID.
Definition at line 705 of file RoomComponent.cs.
RoomTemplate GetMMRoomTemplate | ( | int | id, |
string | name | ||
) |
Returns the Mania Map room template used by the procedural generator.
id | The template ID. |
name | The template name. |
Definition at line 645 of file RoomComponent.cs.
Vector2Int GlobalPositionToCellIndex | ( | Vector3 | position | ) |
Converts the specified global position to the containing cell index. If the cell index does not exist, returns (-1, -1).
position | The global position. |
Definition at line 635 of file RoomComponent.cs.
Vector3 GlobalToGridPosition | ( | Vector3 | globalPosition | ) |
Converts the specified global position to grid coordinates.
globalPosition | The global coordinate position. |
System.ArgumentException | Raised if the room type is not handled. |
Definition at line 569 of file RoomComponent.cs.
Vector2Int GridPositionToCellIndex | ( | Vector3 | position | ) |
Converts the specified grid position to the containing cell index. If the cell index does not exist, returns (-1, -1).
position | The grid position. |
Definition at line 609 of file RoomComponent.cs.
Vector3 GridToLocalPosition | ( | Vector3 | gridPosition | ) |
Converts the specified grid coordinate to local coordinates.
gridPosition | The grid coordinate position. |
System.ArgumentException | Raised if the room type is not handled. |
Definition at line 531 of file RoomComponent.cs.
bool Initialize | ( | LayoutPack | layoutPack, |
Room | roomLayout, | ||
RoomState | roomState, | ||
int | cellLayer, | ||
LayerMask | triggeringLayers, | ||
bool | assignLayoutPosition | ||
) |
Initializes the room. Returns false if the room has already been initialized.
layoutPack | The layout pack. |
roomLayout | The room's layout. |
roomState | The room's layout state. |
cellLayer | The physics layer assigned to cell triggers. |
triggeringLayers | The physics layers that trigger the room cell triggers. |
assignLayoutPosition | If true, the room will have its local position moved to its location within the layout. |
Definition at line 264 of file RoomComponent.cs.
|
static |
Instantiates and initializes a room and returns it.
prefab | The room prefab. |
parent | The parent transform. |
layoutPack | The layout pack. |
roomLayout | The room's layout. |
roomState | The room's layout state. |
cellLayer | The physics layer assigned to cell triggers. |
triggeringLayers | The physics layers that trigger the room cell triggers. |
assignLayoutPosition | If true, the room will have its local position moved to its location within the layout. |
Definition at line 246 of file RoomComponent.cs.
|
static |
Instantiates and initializes a room and returns it.
id | The room ID. |
layoutPack | The layout pack. |
prefab | The room prefab. |
parent | The parent transform. |
assignLayoutPosition | If true, the room will have its local position moved to its location within the layout. |
Definition at line 225 of file RoomComponent.cs.
|
static |
Instantiates and initializes a room asynchronously. Returns the operation handle.
prefab | The room prefab asset reference. |
parent | The parent transform. |
layoutPack | The layout pack. |
roomLayout | The room's layout. |
roomState | The room's layout state. |
cellLayer | The physics layer assigned to cell triggers. |
triggeringLayers | The physics layers that trigger the room cell triggers. |
assignLayoutPosition | If true, the room will have its local position moved to its location within the layout. |
Definition at line 205 of file RoomComponent.cs.
|
static |
Instantiates and initializes a room asynchronously. Returns the operation handle.
id | The room ID. |
layoutPack | The layout pack. |
prefab | The room prefab asset reference. |
parent | The parent transform. |
assignLayoutPosition | If true, the room will have its local position moved to its location within the layout. |
Definition at line 183 of file RoomComponent.cs.
Vector3 LocalCellSize | ( | ) |
Returns the cell size in local coordinates.
System.ArgumentException | Raised if the room type is not handled. |
Definition at line 512 of file RoomComponent.cs.
Vector2Int LocalPositionToCellIndex | ( | Vector3 | position | ) |
Converts the specified local position to the containing cell index. If the cell index does not exist, returns (-1, -1).
position | The local position. |
Definition at line 625 of file RoomComponent.cs.
Vector3 LocalToGridPosition | ( | Vector3 | localPosition | ) |
Converts the specified local coordinate to grid coordinates.
localPosition | The local coordinate position. |
System.ArgumentException | Raised if the room type is not handled. |
Definition at line 550 of file RoomComponent.cs.
|
private |
Sets the room's local position to its position in the layout.
Definition at line 287 of file RoomComponent.cs.
|
private |
Definition at line 138 of file RoomComponent.cs.
|
private |
Definition at line 132 of file RoomComponent.cs.
bool SetCellActivities | ( | Vector2Int | startIndex, |
Vector2Int | endIndex, | ||
CellActivity | activity | ||
) |
Sets the cell activities for the specified index range. No action is taken if one of the indexes is out of range. Returns false if no action is taken.
startIndex | The first index. |
endIndex | The second index. |
activity | The cell activity. |
Definition at line 349 of file RoomComponent.cs.
void SetCellActivity | ( | int | row, |
int | column, | ||
bool | activity | ||
) |
Sets the cell activity for the specified index.
row | The row index. |
column | The column index. |
activity | The cell activity. |
System.IndexOutOfRangeException | Raised if the specified index is out of range. |
Definition at line 408 of file RoomComponent.cs.
void SetCellActivity | ( | int | row, |
int | column, | ||
CellActivity | activity | ||
) |
Sets the cell activity for the specified index.
row | The row index. |
column | The column index. |
activity | The cell activity. |
System.IndexOutOfRangeException | Raised if the specified index is out of range. |
System.NotImplementedException | Raised if the specified cell activity is not handled. |
Definition at line 378 of file RoomComponent.cs.
|
private |
Definition at line 126 of file RoomComponent.cs.
void SizeActiveCells | ( | ) |
Sizes the active cells list to match the room size.
Definition at line 315 of file RoomComponent.cs.
void ValidateRoomFlags | ( | ) |
Validates that the room flag ID's are unique.
DuplicateIdException | Raised if two room flags have the same ID. |
Definition at line 722 of file RoomComponent.cs.
|
private |
Definition at line 62 of file RoomComponent.cs.
|
private |
Definition at line 54 of file RoomComponent.cs.
|
private |
Definition at line 33 of file RoomComponent.cs.
|
private |
Definition at line 83 of file RoomComponent.cs.
|
private |
Definition at line 90 of file RoomComponent.cs.
|
private |
Definition at line 69 of file RoomComponent.cs.
|
private |
Definition at line 76 of file RoomComponent.cs.
|
private |
Definition at line 26 of file RoomComponent.cs.
|
private |
Definition at line 40 of file RoomComponent.cs.
|
private |
Definition at line 47 of file RoomComponent.cs.
|
getset |
A list of active cell rows.
Definition at line 66 of file RoomComponent.cs.
|
getset |
The size of each cell within the grid coordinate system.
Definition at line 58 of file RoomComponent.cs.
|
getset |
The column index.
Definition at line 124 of file RoomComponent.cs.
|
getprivate set |
True if the room has been initialized.
Definition at line 99 of file RoomComponent.cs.
|
getprivate set |
The layout pack.
Definition at line 104 of file RoomComponent.cs.
|
getset |
The room name.
Definition at line 37 of file RoomComponent.cs.
|
getset |
The event invoked when a room cell has been entered. Message includes the enterered cell and the colliding GameObject.
Definition at line 87 of file RoomComponent.cs.
|
getset |
The event invoked when a room cell has been exited. Message includes the exited cell and the colliding GameObject.
Definition at line 94 of file RoomComponent.cs.
|
getset |
An event invoked when the room is initialized.
Definition at line 73 of file RoomComponent.cs.
|
getset |
The event invoked after the room has completed initialization.
Definition at line 80 of file RoomComponent.cs.
|
getprivate set |
The room data.
Definition at line 109 of file RoomComponent.cs.
|
getprivate set |
The room state.
Definition at line 114 of file RoomComponent.cs.
|
getset |
The room template.
Definition at line 30 of file RoomComponent.cs.
The room type.
Definition at line 44 of file RoomComponent.cs.
|
getset |
The row index.
Definition at line 119 of file RoomComponent.cs.
|
getset |
The size of the room grid in rows (x) and columns (y).
Definition at line 51 of file RoomComponent.cs.