Skip to main content

MapBoardDirectRenderer

A class in Root.Township, Alta.Map.

Client: draws a map board straight into a render texture with blits (map, landmarks below the mask, discovered pieces, landmarks above, then a you-are-here icon). Destroys itself on headless servers.

Constructors​

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

Fields​

22 private and internal fields
MemberWhat it is
private static readonly int _DstBlendShader property ID for _DstBlend.
private static readonly int _DstBlendAlphaShader property ID for _DstBlendAlpha.
private static readonly int _MaskColorShader property ID for _MaskColor, set to backgroundColor.
private static readonly int _OffsetScaleShader property ID for _OffsetScale, the position and scale of each blit.
private static readonly int _SrcBlendShader property ID for _SrcBlend.
private static readonly int _SrcBlendAlphaShader property ID for _SrcBlendAlpha.
private Color backgroundColorColour passed to the shader as the mask colour.
private Shader baseShaderShader used for the blit material.
private Texture2D hereIconTexture drawn at the board's own position.
private float hereIconScaleScale of the you-are-here icon. Default 0.02.
private bool isAlwaysRenderingSerialized flag that is never read.
private bool isRenderQueuedTrue while a delayed render is pending.
private bool isVisibleWhether previewRenderer is currently seen by a camera.
private MapLandmarkDisplay landmarkDisplayGives the lists of markers to draw below and above the map mask.
private Texture2D mapThe base map texture.
private MapBoard mapBoardThe MapBoard this draws; gives the offset, scale and active map pieces.
private bool needsToRenderSet when a change came in while hidden, so it renders when next visible.
private Renderer previewRendererRenderer whose material shows the render texture.
private RenderTexture rtThe render texture the map is drawn into.
private Vector2Int rtSizeSize of the render texture. Default 2048 by 2048.
private Vector2Int rtSizeAndroidSerialized size for Android (1024 by 1024). Never read in this build.
private bool wasDestroyedSet in OnDestroy so a delayed RenderMap does nothing.

Methods​

9 private and internal methods
MemberWhat it is
private void Awake()Destroys itself on headless builds. Otherwise renders once and listens for landmark changes and map piece discoveries.
private void CheckRender()Queues a render if the board is visible, otherwise marks that it needs one.
private void CheckRenderDiscover(int arg1, MapPiece arg2)Handler for the map's PieceDiscovered event; calls CheckRender.
private void CheckRenderLandmark(MarkerInfo marker)Handler for the client landmark manager's Changed event; calls CheckRender.
private void OnBecameInvisible()Marks the board as not visible so renders are put off.
private void OnBecameVisible()Marks the board visible and renders if a change came in while hidden.
private void OnDestroy()Releases the render texture and removes the event listeners.
private void QueueRender()Schedules RenderMap 0.5 s later, unless one is already queued.
private void RenderMap()Redraws the whole map into rt, creating it on first use and assigning it to previewRenderer.