How It Works

MapManager and MapRooms


Awake()

When your scene is loaded the MapManager instance in the scene assigns itself to the MapManager.Instance static variable. Thus making itself available to other components.

It then loads any saved map data from PlayerPrefs. Any MapRoomData is registered in the static dictionary MapRoom.allMapRooms via the method MapRoom.AddMapRoom(data).

The MapRoom.allMapRooms dictionary maps fully qualified room names to MapRoomData. A fully qualified room name is a combination of scene name and map name and should be unique.


Start()

On Start each room in the scene registers itself with the MapRoom.allMapRooms dictionary; if the room already exists the content is updated to associate the MapRoom in the scene with the already loaded MapRoomData. If it does not exist new MapRoomData is created.

Once data is loaded the game loop can begin.


Update()

Each tick of the game loop (update) the MapRooms check the location of the Player vs the rooms boundaries. If the player is in the room (and was not previously in the room) the MapRoom informs the MapManager that the player has entered the room (MapManager.Instance.EnterRoom).

Conversely if the player was previously in the room and is no longer in the room then the MapRoom informs the MapManager that the player is no longer in the room (MapManager.Instance.LeaveRoom).

When a Player enters a room that has not yet been revealed, additional behaviour is triggered such as revealing Points of Interest (see Points of Interest below) and sending a Reveal event (see Events below).

Points of Interest

PointsOfInterest are loaded and registered with the MapManager in a similar way to MapRooms. The only major difference is that during load MapRooms scan PointsOfInterest to see if they are within the MapRooms boundaries. If the Point of Interest is within the boundaries of a MapRoom it is associated with that MapRoom.

When a MapRoom is revealed any PointsOfInterest associated with that room are also revealed.

NOTE: A PointOfInterest can be marked as hidden which means it is not revealed when the room is revealed.

NOTE: A PointOfInterest can be marked as revealed which means it is always revealed regardless of the Player having revealed the MapRoom the point of interest occurs in.


MapManager Events

Whenever the state of the map changes the MapManager sends an event. The following events are sent:

Event Description
EnteredRoom Sent when the player enters a room.
LeftRoom Sent when the player leaves a room.
RevealedRoom Sent when a room is revealed (generally when the player entered the room for the first time, although rooms can be revealed by calling RevealRoom directly for example to show a target destination on the map).
PointOfInterestAdded Sent when a point of interest is revealed.
PointOfInterestRemoved Sent when a point of interest is removed from the scene (e.g. when an item is collected or an enemy dies).

 

 

 

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.
Powered by Zendesk