Skip to main content

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.

Constructors​

MemberWhat it is
MapBoard()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

9 private and internal fields
MemberWhat it is
private readonly Dictionary<int, MapPiece> activeMapPiecesClient: map pieces not yet discovered, keyed by piece index. Always empty on headless builds.
private HandHoverPoint handHoverPointHover point players touch to read the board. The server discovers the unlock piece when it's activated.
private static Logger loggerNLog logger for this class.
private Map mapThe map this board shows. Saved and synced.
private Vector2 positionOffsetOffset of the map shown on the board, in pixels of resolution. Saved and synced.
private Vector2 resolutionMap image resolution used to turn positionOffset into the shader offset. Default 2048 by 2048.
private MethodSync syncBoardMethod sync that sends the board's settings to a joining player.
private int unlockPieceIndexIndex of the map piece the board discovers for a player who uses it. Saved and synced.
private float zoomZoom of the map on the board, from 1 to 5. Saved and synced.

Properties​

MemberWhat 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​

MemberWhat it is
event Action<MapBoard> SetupAsClientRaised on the client once the board has its settings and map pieces.

Methods​

MemberWhat 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
MemberWhat 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: