ManiaMap.Unity
Procedural generation of metroidvania style maps for Unity.
CellArea3D.cs
1using UnityEngine;
2
4{
8 [RequireComponent(typeof(BoxCollider))]
9 public class CellArea3D : CellArea
10 {
14 public BoxCollider Collider { get; private set; }
15
16 private void Awake()
17 {
18 Collider = GetComponent<BoxCollider>();
19 }
20
29 public static CellArea3D InstantiateCellArea3D(int row, int column, RoomComponent room,
30 int cellLayer, LayerMask triggeringLayers)
31 {
32 var obj = new GameObject("Cell Area 3D");
33 obj.transform.SetParent(room.transform);
34 obj.transform.localPosition = room.CellCenterLocalPosition(row, column);
35
36 var area = obj.AddComponent<CellArea3D>();
37 area.Initialize(row, column, room);
38
39 var collider = area.Collider;
40 collider.gameObject.layer = cellLayer;
41 collider.isTrigger = true;
42 collider.size = room.LocalCellSize();
43 collider.includeLayers = triggeringLayers;
44 collider.excludeLayers = ~triggeringLayers;
45
46 return area;
47 }
48
53 private void OnTriggerEnter(Collider collision)
54 {
55 Room.RoomState.SetCellVisibility(Row, Column, true);
56 Room.OnCellAreaEntered.Invoke(this, collision.gameObject);
57 }
58
63 private void OnTriggerExit(Collider collision)
64 {
65 Room.OnCellAreaExited.Invoke(this, collision.gameObject);
66 }
67 }
68}
A 3D trigger to detect if an object on a monitored physics layer mask enters or exits a RoomComponent...
Definition: CellArea3D.cs:10
void OnTriggerExit(Collider collision)
Calls the OnCellAreaExited event on the containing RoomComponent.
Definition: CellArea3D.cs:63
BoxCollider Collider
The attached box collider.
Definition: CellArea3D.cs:14
void OnTriggerEnter(Collider collision)
Sets the RoomState cell visibility to true and calls the OnCellAreaEntered event on the containing Ro...
Definition: CellArea3D.cs:53
static CellArea3D InstantiateCellArea3D(int row, int column, RoomComponent room, int cellLayer, LayerMask triggeringLayers)
Instantiates a new cell area within the specified room.
Definition: CellArea3D.cs:29
The base class for cell trigger areas.
Definition: CellArea.cs:9
int Row
The row index corresponding to the area.
Definition: CellArea.cs:13
RoomComponent Room
The containing room.
Definition: CellArea.cs:23
void Initialize(int row, int column, RoomComponent room)
Initializes the base properties for the area.
Definition: CellArea.cs:55
A component for creating a room.
Vector3 LocalCellSize()
Returns the cell size in local coordinates.
Vector3 CellCenterLocalPosition(int row, int column)
Returns the cell center for the specified index in local coordinates.
CellAreaTriggerEvent OnCellAreaEntered
The event invoked when a room cell has been entered. Message includes the enterered cell and the coll...
RoomState RoomState
The room state.
CellAreaTriggerEvent OnCellAreaExited
The event invoked when a room cell has been exited. Message includes the exited cell and the collidin...