MapManager
A class in Root.Township, Alta.Map.
Tracks which map pieces each player has discovered, either one shared map for everyone or a map per player saved in player data. Singleton MapManager.Instance; the server loads and saves, clients keep one local copy.
- Listed in World, chunks and saving
- Inherits or implements
NetworkEntityBehaviour - Nested types
MapPieceIdentifier - Documented in Map and landmarks
Constructors
| Member | What it is |
|---|---|
MapManager() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
7 private and internal fields
| Member | What it is |
|---|---|
private bool isUsingSharedMap | Backing field for IsUsingSharedMap. |
private static Logger logger | Logger for this class; discovery is logged at Info. |
private Dictionary<IPlayer, PlayerMapManager> managers | Server: map manager for each player, when maps are not shared. |
private PlayerMapManager singleManager | The shared map on the server, or the local player's map on a client. |
private MethodSyncClass<PlayerMapManager> syncMapManager | Method sync (SyncA) for the whole map. |
private MethodSyncStruct<MapManager.MapPieceIdentifier> syncPieceDiscovery | Method sync (SyncB) for one discovered piece. |
private IUnityUpdateMethod updateMovingLandmarks | Update handle; not used in this class. |
Properties
| Member | What it is |
|---|---|
static MapManager Instance { get; private set; } | The active map manager. |
bool IsUsingSharedMap { get; } | Whether all players share one map. |
Methods
| Member | What it is |
|---|---|
async void DiscoverPiece(IPlayer player, Map map, int pieceIndex) | Server: marks a map piece found for the player and sends it to everyone (shared map) or just that player. |
async Task<PlayerMapManager> GetMapManager(IPlayer player) | Gets the shared map manager, or loads the player's own one from their map save file. |
PlayerMapManager GetSharedManager() | Returns the single manager: the shared map on the server, or the local map on a client. |
override async void Initialize() | Creates the syncs; the server loads the shared map or the host player's map, and clients start with an empty map. |
override async void OnConnected(Player player) | Server: loads the player's map (or uses the shared one) and sends it to them. |
override async void OnDisconnected(Player player) | Server: writes and unloads the player's map save file and forgets their manager. |
4 private and internal methods
| Member | What it is |
|---|---|
private void Awake() | Sets Instance, or destroys itself if another one exists. |
private async Task<PlayerMapManager> SetupPlayer(IPlayer player) | Server: loads a player's map save file and stores a manager for them. |
private void SyncMapManager(IPlayer player, Stream stream, PlayerMapManager manager) | Sends a whole map manager; clients read it into their single local manager. |
private void SyncPieceDiscovery(IPlayer player, Stream stream, MapManager.MapPieceIdentifier piece) | Sends one discovered map piece (map and index 0 to 127); clients mark it found. |