Table of Contents

Class MapModeManager

Namespace
Map.MapModes
Assembly
MapAssembly.dll

Central manager for the map mode system Handles mode switching, texture updates, and handler coordination Performance: <0.1ms mode switching, efficient texture scheduling

public class MapModeManager : MonoBehaviour
Inheritance
object
MapModeManager

Properties

CurrentMode

public MapMode CurrentMode { get; }

Property Value

MapMode

IsInitialized

public bool IsInitialized { get; }

Property Value

bool

Methods

CopyRenderTextureToArray(int, RenderTexture)

Copy a RenderTexture to the texture array using GPU-to-GPU copy. This is the FAST path - no CPU roundtrip, stays entirely on GPU. Called by GradientMapMode after compute shader dispatch.

public void CopyRenderTextureToArray(int arrayIndex, RenderTexture sourceTexture)

Parameters

arrayIndex int
sourceTexture RenderTexture

ForceTextureUpdate()

Force an immediate texture update for the current map mode

public void ForceTextureUpdate()

ForceUpdateIfActive(IMapModeHandler)

Force texture update only if the given handler is currently active. Called by GradientMapMode.MarkDirty() to trigger event-driven updates.

public void ForceUpdateIfActive(IMapModeHandler handler)

Parameters

handler IMapModeHandler

GetCustomModeArrayIndex(int)

Get the array index for a registered custom mode. Returns -1 if not registered.

public int GetCustomModeArrayIndex(int customModeId)

Parameters

customModeId int

Returns

int

GetHandler(MapMode)

Get a specific map mode handler (for GAME layer to mark dirty) Returns null if handler not registered

public IMapModeHandler GetHandler(MapMode mode)

Parameters

mode MapMode

Returns

IMapModeHandler

GetMapDimensions()

Get the dimensions of the map mode texture array. GAME map modes need this to create correctly sized pixel arrays.

public (int width, int height) GetMapDimensions()

Returns

(int x, int y)

GetProvinceTooltip(ushort)

public string GetProvinceTooltip(ushort provinceId)

Parameters

provinceId ushort

Returns

string

Initialize(GameState, Material, ProvinceMapping, object)

Initialize the map mode system ENGINE provides MECHANISM, GAME controls WHEN to initialize Called by GAME layer after handlers are registered

public void Initialize(GameState gameStateRef, Material material, ProvinceMapping mapping, object gameSystem = null)

Parameters

gameStateRef GameState
material Material
mapping ProvinceMapping
gameSystem object

Optional game-specific province system - engine passes through without knowing type

RebindTextures()

Rebind all map mode textures to the material Call this after other systems rebind base textures to prevent losing map mode texture bindings

public void RebindTextures()

RegisterCustomMapMode(int)

Register a custom map mode and get its array index. Called by GAME layer when creating custom map modes.

public int RegisterCustomMapMode(int customModeId)

Parameters

customModeId int

Unique ID for this custom mode (typically ShaderModeID from handler)

Returns

int

Array index for this mode's texture slice, or -1 if full

RegisterHandler(MapMode, IMapModeHandler)

Register a map mode handler - called by GAME layer during initialization Enables dependency injection: ENGINE provides mechanism, GAME provides policy

public void RegisterHandler(MapMode mode, IMapModeHandler handler)

Parameters

mode MapMode
handler IMapModeHandler

RequestDeferredUpdate(IMapModeHandler)

Request a deferred texture update for next frame. Multiple requests within same frame are batched into single update. Called by GradientMapMode.MarkDirty() to prevent multiple rebuilds per tick.

public void RequestDeferredUpdate(IMapModeHandler handler)

Parameters

handler IMapModeHandler

SetMapMode(MapMode, bool)

public void SetMapMode(MapMode mode, bool forceUpdate = false)

Parameters

mode MapMode
forceUpdate bool

UpdateCustomMapModeTexture(int, Color32[])

Update a custom map mode's texture data (CPU pixel array version). Called by GAME map mode handlers when their data changes (dirty). NOTE: This is SLOW due to GPU→CPU→GPU roundtrip. Prefer BindCustomMapModeRenderTexture().

public void UpdateCustomMapModeTexture(int arrayIndex, Color32[] pixels)

Parameters

arrayIndex int

Index returned from RegisterCustomMapMode

pixels Color32[]

Color data for the entire map

UpdateMaterial(Material)

Update material reference when material is swapped Called by GAME layer (VisualStyleManager) when material changes

public void UpdateMaterial(Material newMaterial)

Parameters

newMaterial Material