MapBoard
A class in Root.Township, Alta.Map.
A board in the world that shows a map and, when a player touches its hover point, reveals one map piece for them. The server saves which map, piece, offset and zoom; clients get them synced.
- Listed in World, chunks and saving
- Inherits or implements
NetworkEntityBehaviour,ISavable<MapBoardSaveData1>,ISavableSave<MapBoardSaveData1>,ISavableSaveBase - Derived types
MapBoardSaveData1
Constructors
| Member | What it is |
|---|---|
MapBoard() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
9 private and internal fields
| Member | What it is |
|---|---|
private readonly Dictionary<int, MapPiece> activeMapPieces | Client: map pieces not yet discovered, keyed by piece index. Always empty on headless builds. |
private HandHoverPoint handHoverPoint | Hover point players touch to read the board. The server discovers the unlock piece when it's activated. |
private static Logger logger | NLog logger for this class. |
private Map map | The map this board shows. Saved and synced. |
private Vector2 positionOffset | Offset of the map shown on the board, in pixels of resolution. Saved and synced. |
private Vector2 resolution | Map image resolution used to turn positionOffset into the shader offset. Default 2048 by 2048. |
private MethodSync syncBoard | Method sync that sends the board's settings to a joining player. |
private int unlockPieceIndex | Index of the map piece the board discovers for a player who uses it. Saved and synced. |
private float zoom | Zoom of the map on the board, from 1 to 5. Saved and synced. |
Properties
| Member | What it is |
|---|---|
IEnumerable<MapPiece> ActiveMapPieces { get; } | Client: map pieces the shared map manager had not discovered when the board was set up. Each is removed when discovered. |
Map Map { get; } | The map this board shows. |
Vector4 MapOffsetScale { get; } | Offset (divided by resolution) and zoom packed into a Vector4 for the map shader. |
float ResolutionX { get; } | The board's horizontal resolution (2048 by default), also used to scale MapOffsetScale. |
Events
| Member | What it is |
|---|---|
event Action<MapBoard> SetupAsClient | Raised on the client once the board has its settings and map pieces. |
Methods
| Member | What it is |
|---|---|
override void Initialize() | Sets up the board sync message. |
override void InitializeAsServer(SpawnData spawnData) | Server: discovers the board's map piece for whoever activates its hand hover point. |
void InteractionStarted(IPlayer player) | Discovers the board's unlock piece for the player through the MapManager. |
override void OnConnected(Player player) | Server: sends the board settings to the joining player. |
Vector2 WorldToMapPosition(Vector2 worldPosition) | Turns a world XZ position into a board position centred on 0, scaled by zoom. |
11 private and internal methods
| Member | What it is |
|---|---|
private void DiscoverMapPiece(int index, MapPiece mapPiece) | Client: drops a piece from activeMapPieces when the map reports it discovered. |
private void InitializeForClient() | Client: after the board sync arrives, lists the undiscovered pieces, listens for discoveries, sets up the hover attract check and raises SetupAsClient. |
private bool IsMapContentAvailable() | True while this board's unlock piece is still undiscovered for the shared map manager. Drives the hand hover attract effect. |
private void ListenToMapDiscoveries() | Subscribes DiscoverMapPiece to the map's PieceDiscovered event. |
private void OnDestroy() | Unsubscribes from the map's PieceDiscovered event (not on headless builds). |
private void OnValidate() | Editor: logs that the map can't be changed while playing. |
private void SetupMap() | Logs an error if no map is set. Does nothing else. |
private void SetupMapPiece(int index, MapPiece piece) | Client: adds one undiscovered piece to activeMapPieces. Skipped on headless builds. |
private void SetupMapPieces(PlayerMapManager mapManager) | Adds every piece the map manager hasn't discovered yet to activeMapPieces. |
private void SyncBoard(IPlayer player, Stream stream) | Sends the map, unlock piece index (0 to 127), offset and zoom. On a client with a local player, reading it runs InitializeForClient. |
private static float UnclampedInverseLerp(float a, float b, float value) | Inverse lerp that doesn't clamp to 0 to 1, used by WorldToMapPosition. |
Used in
Members of other types that take, return or hold a MapBoard: