X Tutup

Scripting Reference (C#)

advanced scripting

World Map 2D Edition · Scripting Support (C#)

Class: All members on this page belong to the WorldMap2D component (namespace WPMF). Access via WorldMap2D.instance.
Tip: Check the demo scenes included in the asset for practical scripting examples covering countries, provinces, cities, markers, and navigation.

Getting Started

Add using WPMF; at the top of your script. Access the map singleton with:

using WPMF;

WorldMap2D map = WorldMap2D.instance;

You can also check if an instance exists without triggering creation:

static bool instanceExists { get; }

Returns true if a WorldMap2D component exists in the scene.

Data Structures

The main data types you'll interact with:

Country

Represents a country. Key fields: name, continent, center (Vector2), regions (List<Region>), provinces (Province[]), hidden, customLabel, labelColor, labelVisible, labelRotation.

Province

Represents a province/state. Key fields: name, countryIndex, center (Vector2), regions (List<Region>), mainRegionIndex.

City

Represents a city. Fields: name, province, countryIndex, unity2DLocation (Vector2), population, cityClass (CITY_CLASS enum), isVisible.

MountPoint

A custom point of interest. Fields: name, type (int), countryIndex, provinceIndex, unity2DLocation (Vector2), customTags (Dictionary<string, string>).

Region

A contiguous area of a country or province. Key fields: points (Vector3[]), center (Vector2), rect2D (Rect), neighbours (List<Region>), customMaterial.

Enumerations

CITY_CLASS

CITY = 1, REGION_CAPITAL = 2, COUNTRY_CAPITAL = 4

FRONTIERS_DETAIL

Low = 0, High = 1

EARTH_STYLE

Natural, Alternate1, Alternate2, Alternate3, SolidColor, NaturalHighRes, NaturalScenic, NaturalHighRes16K, NaturalScenic16K

Events

event OnCountryEvent OnCountryEnter(int countryIndex, int regionIndex)

Triggered when the pointer enters a country.

event OnCountryEvent OnCountryExit(int countryIndex, int regionIndex)

Triggered when the pointer exits a country.

event OnCountryEvent OnCountryClick(int countryIndex, int regionIndex)

Triggered when a country is clicked.

event OnCountryHighlightEvent OnCountryHighlight(int countryIndex, int regionIndex, ref bool allowHighlight)

Triggered before highlighting a country. Signature includes ref bool allowHighlight to cancel.

event OnProvinceEvent OnProvinceEnter(int provinceIndex, int regionIndex) / OnProvinceExit / OnProvinceClick

Province interaction events.

event OnProvinceHighlightEvent OnProvinceHighlight(int provinceIndex, int regionIndex, ref bool allowHighlight)

Triggered before highlighting a province. Set allowHighlight = false to cancel.

event OnCityEnter OnCityEnter(int cityIndex) / OnCityExit OnCityExit / OnCityClick OnCityClick

City interaction events.

event OnSimpleMapEvent OnDragStart() / OnDragEnd

Fired when the user starts or stops dragging the map.

event OnClickEvent OnClick(Vector2 localPoint)

General map click event.

Marker Events (ViewportClickHandler)

The ViewportClickHandler component (namespace WPMF.Demos) can be attached to sprites or 3D objects added via the viewport to receive pointer interaction events. Set the map reference and subscribe to these callbacks:

OnMarkerPointerClickEvent OnMarkerMouseDown(int buttonIndex)

Fired when a mouse button is pressed on the marker. Button 0 = left, 1 = right.

OnMarkerPointerClickEvent OnMarkerMouseUp(int buttonIndex)

Fired when a mouse button is released on the marker.

OnMarkerEvent OnMarkerMouseEnter()

Fired when the pointer enters the marker area.

OnMarkerEvent OnMarkerMouseExit()

Fired when the pointer leaves the marker area.

Country Properties

Country[] countries

Array of all countries.

Country countryHighlighted { get; }

The country currently under the pointer (or null).

int countryHighlightedIndex { get; }

Index of the highlighted country (-1 if none).

int countryLastClicked { get; }

Index of the last country clicked.

bool enableCountryHighlight { get; set; }

Enable or disable country highlighting on hover.

bool showFrontiers { get; set; }

Show or hide country borders.

Color frontiersColor { get; set; }

Color of country border lines.

bool showCountryNames { get; set; }

Show or hide country labels.

Color countryLabelsColor { get; set; }

Color of country name labels.

float countryLabelsSize { get; set; }

Size of country name labels.

Region countryRegionHighlighted read-only

Returns the currently highlighted country region object, or null if none.

int countryRegionHighlightedIndex read-only

Returns the region index of the currently highlighted country (-1 if none).

int countryRegionLastClicked read-only

Returns the region index of the last clicked country.

bool highlightAllCountryRegions

When true, highlighting a country highlights all of its regions, not just the one under the pointer.

float countryHighlightMaxScreenAreaSize

Maximum screen area ratio (0–1) a highlighted country can fill. Prevents large countries from flooding the screen with color.

bool frontiersThinLines

When true, frontier lines remain thin even when zoomed in.

Color frontiersColorOuter

Outer color for country frontier lines (creates a border glow effect).

bool showOutline

Toggle thicker outline visibility around country frontiers.

Color outlineColor

Color of the thicker country outline.

Color fillColor

Fill color used when the pointer hovers over a country region.

FRONTIERS_DETAIL frontiersDetail

Level of detail for country frontiers (Low or High).

float countryLabelsAbsoluteMinimumSize

Absolute minimum size for country labels. Labels smaller than this value will not be rendered.

bool showLabelsShadow

Draws a shadow beneath country labels. Set the shadow color with countryLabelsShadowColor.

Color countryLabelsShadowColor

Color of the shadow drawn beneath country labels.

Font countryLabelsFont

Gets or sets the TrueType font used for country labels.

bool countryLabelSpread

When true, country names include extra spacing to spread across large country surfaces.

Country Methods

int GetCountryIndex(string countryName)

Returns the index of a country by name, or -1 if not found.

int GetCountryIndex(Vector2 localPosition)

Returns the country index at a given map position.

int GetCountryNearPoint(Vector2 localPosition)

Returns the closest country to a map position.

string[] GetCountryNames(bool groupByContinent)

Returns an array of all country names, optionally grouped by continent.

List<Country> CountryNeighbors(int countryIndex)

Returns all countries that share a border with the given country.

float GetCountryRegionZoomExtents(int countryIndex)

Returns the zoom level needed to fit the country's main region on screen.

bool CountryRename(string oldName, string newName)

Renames a country.

int CountryAdd(Country country)

Adds a new country and returns its index.

bool CountryDelete(int countryIndex, bool deleteDependencies)

Deletes a country. If deleteDependencies is true, also removes provinces, cities, and mount points.

int GetCountryIndex(Country country)

Returns the index of a country by its object reference, or -1 if not found.

bool GetCountryIndex(Ray ray, out int countryIndex, out int regionIndex)

Returns the country and region index at a screen ray position. Returns true if a country was hit.

List<Country> CountryNeighborsOfMainRegion(int countryIndex)

Returns all countries that share a border with the main region of the given country.

List<Country> CountryNeighborsOfCurrentRegion()

Returns all countries neighboring the currently highlighted region.

float GetCountryRegionZoomExtents(int countryIndex, int regionIndex)

Returns the zoom level needed to fit a specific region of a country on screen.

bool FlyToCountry(Country country)

Navigates to a country by object reference. Returns false if not found.

bool FlyToCountry(string name)

Navigates to a country by name. Returns false if not found.

bool FlyToCountry(string name, float duration)

Navigates to a country by name with custom duration.

void FlyToCountry(int countryIndex)

Navigates to a country by index using the default navigation time.

void FlyToCountry(int countryIndex, float duration)

Navigates to a country by index with custom duration.

bool ToggleCountrySurface(string name, bool visible, Color color)

Colorizes all regions of a country by name. Returns false if country not found.

void ToggleCountrySurface(int countryIndex, bool visible, Color color, Texture2D texture, bool applyTextureToAllRegions)

Colorizes all regions of a country with an optional texture.

void ToggleCountrySurface(int countryIndex, bool visible, Color color, Texture2D texture, Vector2 textureScale, Vector2 textureOffset, float textureRotation, bool applyTextureToAllRegions)

Full overload for colorizing a country with texture, scale, offset, and rotation parameters.

GameObject ToggleCountryRegionSurfaceHighlight(int countryIndex, int regionIndex, Color color, bool drawOutline)

Temporarily highlights a specific country region with a given color. Returns the surface GameObject.

GameObject ToggleCountryMainRegionSurface(string countryName, bool visible, Color color)

Toggles the surface of the main region of a country by name.

GameObject ToggleCountryMainRegionSurface(int countryIndex, bool visible, Texture2D texture)

Applies a texture to the main region of a country.

GameObject ToggleCountryMainRegionSurface(int countryIndex, bool visible, Color color, Texture2D texture, Vector2 textureScale, Vector2 textureOffset, float textureRotation)

Full overload for the main region surface with texture, scale, offset, and rotation.

GameObject ToggleCountryRegionSurface(int countryIndex, int regionIndex, bool visible, Color color, Texture2D texture, Vector2 textureScale, Vector2 textureOffset, float textureRotation)

Full overload for coloring/texturing a specific country region.

void SetCountryRegionMaterial(int countryIndex, int regionIndex, Material material)

Overrides the material used by a specific country region.

void HideCountryRegionSurface(int countryIndex, int regionIndex)

Hides the surface of a specific country region.

void HideCountrySurface(string countryName)

Hides all surfaces of a country by name.

void HideCountryRegionHighlights(bool destroyCachedSurfaces)

Disables all country region highlights. If true, destroys cached surface GameObjects.

void BlinkCountryMainRegion(int countryIndex, Color color1, Color color2, float duration, float blinkingSpeed)

Applies a blinking color animation to only the main region of a country.

void BlinkCountry(int countryIndex, int regionIndex, Color color1, Color color2, float duration, float blinkingSpeed)

Applies a blinking animation to a specific region of a country.

void HideContinentSurface(string continentName)

Hides all country surfaces belonging to the specified continent.

bool CountryDeleteProvinces(int countryIndex)

Deletes all provinces belonging to a country.

void CountriesDeleteFromContinent(string continentName)

Deletes all countries (and their dependencies) that belong to a continent.

void RefreshCountryDefinition(int countryIndex, List<Region> filterRegions)

Recalculates boundaries and optimizes frontiers for a country. Used after modifying country geometry.

void RefreshCountryGeometry(int countryIndex)

Recalculates the bounding rect, center, and main region index for a country.

void OptimizeFrontiers()

Recalculates and caches frontier meshes. Call after modifying country border data.

Country Surface & Visual Effects

void ToggleCountrySurface(int countryIndex, bool visible, Color color)

Shows or hides a colored overlay on a country. Additional overloads accept a Texture2D, scale, offset, and rotation.

GameObject ToggleCountryMainRegionSurface(int countryIndex, bool visible, Color color)

Toggles the surface of only the main region of a country. Returns the surface GameObject.

GameObject ToggleCountryRegionSurface(int countryIndex, int regionIndex, bool visible, Color color)

Toggles the surface of a specific region of a country.

void HideCountrySurface(int countryIndex)

Hides all surfaces for a country.

void HideCountrySurfaces()

Hides all country surfaces on the map.

void BlinkCountry(int countryIndex, Color color1, Color color2, float duration, float blinkingSpeed)

Applies a blinking color animation to a country.

void ToggleContinentSurface(string continentName, bool visible, Color color)

Colors an entire continent.

Province Properties & Methods

Province[] provinces { get; set; }

Array of all provinces/states.

bool showProvinces { get; set; }

Show or hide province borders.

int GetProvinceIndex(int countryIndex, string provinceName)

Returns the province index by name within a country.

int GetProvinceIndex(Vector2 localPosition)

Returns the province at a given map position.

Province[] GetProvinces(int countryIndex)

Returns all provinces belonging to a country.

List<Province> ProvinceNeighbors(int provinceIndex)

Returns all neighboring provinces.

void ToggleProvinceSurface(int provinceIndex, bool visible, Color color)

Shows or hides a colored overlay on a province.

void BlinkProvince(int provinceIndex, Color color1, Color color2, float duration, float blinkingSpeed)

Applies a blinking animation to a province.

bool DrawProvinces(int countryIndex, bool includeNeighbors, bool forceRefresh)

Draws province borders for a specific country.

Province provinceHighlighted read-only

Returns the province currently under the pointer, or null if none.

int provinceHighlightedIndex read-only

Returns the index of the currently highlighted province (-1 if none).

Region provinceRegionHighlighted read-only

Returns the currently highlighted province region object.

int provinceRegionHighlightedIndex read-only

Returns the region index of the currently highlighted province.

int provinceLastClicked read-only

Returns the index of the last clicked province.

int provinceRegionLastClicked read-only

Returns the region index of the last clicked province.

bool enableProvinceHighlight

Enable or disable province highlighting on hover.

bool drawAllProvinces

When true, draws province borders for all countries, not just the selected one.

Color provincesFillColor

Fill color used when the pointer hovers over a province region.

Color provincesColor

Color for province border lines.

void HideProvinces()

Hides all province borders and clears any province highlight.

int GetProvinceIndex(Province province)

Returns the index of a province by its object reference.

int GetProvinceIndex(string provinceName, string countryName)

Returns the province index by province and country name.

int GetProvinceNearPoint(Vector2 localPosition)

Returns the province at or nearest to a map position.

bool GetProvinceRegionIndex(Vector2 localPosition, out int provinceIndex, out int provinceRegionIndex)

Gets both province and region index at a given map coordinate.

bool GetProvinceIndex(Ray ray, out int provinceIndex, out int regionIndex)

Returns the province index at a screen ray position.

List<Province> ProvinceNeighborsOfMainRegion(int provinceIndex)

Returns all provinces sharing a border with the main region of the given province.

List<Province> ProvinceNeighborsOfCurrentRegion()

Returns all provinces neighboring the currently highlighted province region.

bool ProvinceRename(int countryIndex, string oldName, string newName)

Renames a province. Returns false if not found or name already exists.

bool ProvinceAdd(Province province)

Adds a properly initialized province to the provinces array and its parent country.

void BlinkProvince(int provinceIndex, int regionIndex, Color color1, Color color2, float duration, float blinkingSpeed)

Applies a blinking animation to a specific province region.

bool FlyToProvince(string name)

Navigates to a province by name. Returns false if not found.

bool FlyToProvince(string countryName, string provinceName, float duration)

Navigates to a province by country and province name with custom duration.

bool FlyToProvince(string countryName, string provinceName, float duration, float zoomLevel)

Navigates to a province by country and province name with custom duration and zoom level.

bool FlyToProvince(int provinceIndex)

Navigates to a province by index.

bool FlyToProvince(int provinceIndex, float duration)

Navigates to a province by index with custom duration.

void ToggleProvinceSurface(string provinceName, string countryName, bool visible, Color color)

Colorizes a province by province and country name.

GameObject ToggleProvinceRegionSurfaceHighlight(int provinceIndex, int regionIndex, Color color)

Temporarily highlights a specific province region. Returns the surface GameObject.

void HideProvinceRegionHighlights(bool destroyCachedSurfaces)

Disables all province region highlights. If true, destroys cached surfaces.

GameObject ToggleProvinceRegionSurface(int provinceIndex, int regionIndex, bool visible, Color color)

Colorizes a specific region of a province. Returns the surface GameObject.

void HideProvinceSurfaces()

Hides all colorized province surfaces on the map.

void HideProvinceSurfaces(int provinceIndex)

Hides all colorized regions of a specific province.

void HideProvinceRegionSurface(int provinceIndex, int regionIndex)

Hides the surface of a specific province region.

string[] GetProvinceNames(bool groupByCountry)

Returns an array of all province names, optionally grouped by country.

string[] GetProvinceNames(int countryIndex)

Returns an array of province names for a specific country.

List<Province> GetProvinces(Region region)

Returns provinces whose center is contained in a given region.

void ProvincesDeleteOfSameContinent(string continentName)

Deletes all provinces belonging to countries in the specified continent.

void ProvincesDelete(int countryIndex)

Deletes all provinces from a specific country.

float GetProvinceRegionZoomExtents(int provinceIndex)

Returns the zoom level needed to fit a province's main region on screen.

float GetProvinceRegionZoomExtents(int provinceIndex, int regionIndex)

Returns the zoom level needed to fit a specific province region on screen.

void SetProvinceRegionMaterial(int provinceIndex, int regionIndex, Material material)

Overrides the material used by a specific province region.

void RefreshProvinceDefinition(int provinceIndex)

Recalculates boundaries for a province. Used after modifying province geometry.

void RefreshProvinceGeometry(int provinceIndex)

Recalculates the bounding rect, center, and main region index for a province.

City Properties & Methods

List<City> cities

List of all cities in the map.

bool showCities { get; set; }

Show or hide city markers.

int GetCityIndex(string cityName)

Returns the index of a city by name.

int GetCityIndex(int countryIndex, string cityName)

Returns the city index within a specific country.

List<City> GetCities(Region region)

Returns all cities within a given region.

void ToggleCityHighlight(int cityIndex, Color color, bool highlighted)

Highlights or un-highlights a city marker.

void BlinkCity(int cityIndex, Color color1, Color color2, float duration, float blinkingSpeed)

Applies a blinking animation to a city marker.

City cityHighlighted read-only

Returns the city currently under the pointer, or null if none.

int cityHighlightedIndex read-only

Returns the index of the currently highlighted city (-1 if none).

int cityLastClicked read-only

Returns the index of the last clicked city.

CITY_CLASS_FILTER cityClassFilter

Filters which classes of cities are displayed (Any, RegionCapitals, CountryCapitals, RegionAndCountryCapitals).

Color citiesColor

Global color for normal city markers.

Color citiesRegionCapitalColor

Global color for region capital markers.

Color citiesCountryCapitalColor

Global color for country capital markers.

float cityIconSize

Size of the city marker icons.

float cityHitTestRadius

Hit-test radius multiplier for city markers. Adjust when the map scale changes.

int minPopulation

Minimum population threshold for displaying cities. Cities below this value are hidden.

int cityClassAlwaysShow

Bit flags specifying city classes that are always shown regardless of population filter. Uses CITY_CLASS_FILTER_REGION_CAPITAL_CITY (2) and CITY_CLASS_FILTER_COUNTRY_CAPITAL_CITY (4).

int numCitiesDrawn read-only

Number of cities currently drawn on the map.

void CitiesDeleteFromContinent(string continentName)

Deletes all cities belonging to countries in the specified continent.

bool GetCityIndex(Ray ray, out int cityIndex)

Returns the city index at a screen ray position.

void HideCityHighlights()

Resets all city markers to their default colors.

string[] GetCityNames()

Returns a sorted array of all city names.

string[] GetCityNames(int countryIndex)

Returns a sorted array of city names for a specific country.

bool FlyToCity(string name)

Navigates to a city by name. Returns false if not found.

bool FlyToCity(string name, float duration)

Navigates to a city by name with custom duration.

bool FlyToCity(string name, float duration, float zoomLevel)

Navigates to a city by name with custom duration and zoom level.

void FlyToCity(int cityIndex)

Navigates to a city by index using the default navigation time.

void FlyToCity(int cityIndex, float duration)

Navigates to a city by index with custom duration.

Navigation & Camera

void FlyToCountry(int countryIndex, float duration, float zoomLevel)

Smoothly navigates the camera to center on a country. Also accepts a country name.

bool FlyToProvince(int provinceIndex, float duration, float zoomLevel)

Smoothly navigates the camera to center on a province.

void FlyToCity(int cityIndex, float duration, float zoomLevel)

Smoothly navigates the camera to center on a city.

void FlyToLocation(Vector2 destination, float duration, float zoomLevel)

Navigates to a specific map position. Also accepts x,y floats or latitude/longitude.

void FlyToLatLon(float lat, float lon, float duration, float zoomLevel)

Navigates to latitude/longitude coordinates.

void SetZoomLevel(float zoomLevel)

Immediately sets the zoom level.

float GetZoomLevel()

Returns the current zoom level.

void CenterMap()

Centers the map view.

bool isFlying { get; }

Returns true while a FlyTo animation is in progress.

float navigationTime { get; set; }

Default duration (in seconds) for FlyTo animations.

bool fitWindowWidth

When true, the map scales to fill the window width.

bool fitWindowHeight

When true, the map scales to fill the window height.

Vector2 flyToScreenCenter

Screen position (0–1) used as the center target for FlyTo operations.

void FlyToLocation(Vector2 destination, float duration)

Navigates to a map position with custom duration.

void FlyToLocation(float x, float y)

Navigates to a map position specified by x,y coordinates.

void FlyToLocation(float x, float y, float duration)

Navigates to x,y with custom duration.

void FlyToLocation(float x, float y, float duration, float zoomLevel)

Navigates to x,y with custom duration and zoom level.

Grid & Cursor

bool showCursor

Toggle visibility of the crosshair cursor lines on the map.

Color cursorColor

Color of the cursor crosshair lines.

bool cursorFollowMouse

When true, the cursor lines follow the mouse position over the map.

Vector3 cursorLocation

Gets or sets the cursor crosshair position in map local coordinates.

bool showLatitudeLines

Toggle visibility of latitude grid lines.

int latitudeStepping

Spacing in degrees between latitude lines (5–45).

bool showLongitudeLines

Toggle visibility of longitude grid lines.

int longitudeStepping

Spacing in degrees between longitude lines (5–45).

Color gridLinesColor

Color of the latitude and longitude grid lines.

Markers & Lines

void AddMarker(GameObject marker, Vector3 planeLocation, float markerScale)

Adds a custom marker at a map position.

GameObject AddLine(Vector2 start, Vector2 end, Color color, float arcElevation, float duration, float lineWidth, float fadeOutAfter)

Draws an animated line between two map positions. Returns the line GameObject.

void ClearMarkers()

Removes all custom markers from the map.

void ClearLineMarkers()

Removes all lines from the map.

Coordinate Conversion

Static methods in the WPMF.Conversion class:

static Vector2 GetLocalPositionFromLatLon(float lat, float lon)

Converts latitude/longitude to local map position.

static Vector2 GetLatLonFromLocalPosition(Vector2 position)

Converts a local map position back to latitude/longitude.

static float Distance(float latDec1, float lonDec1, float latDec2, float lonDec2)

Calculates the real-world distance in kilometers between two lat/lon coordinates.

static void GetTileFromLatLon(int zoomLevel, float lat, float lon, out int xtile, out int ytile)

Gets tile coordinates for a given lat/lon at a specific zoom level.

static Vector2 GetLatLonFromTile(float x, float y, int zoomLevel)

Converts tile coordinates back to lat/lon.

static Vector3 GetLocalPositionFromLatLon(Vector2 latLon)

Converts a lat/lon Vector2 to a local map position (Vector3).

static Vector2 GetUVFromLatLon(float lat, float lon)

Converts latitude/longitude to UV texture coordinates.

static Vector2 GetLatLonFromBillboard(Vector2 position)

Converts billboard coordinates to latitude/longitude.

static Vector2 GetLatLonFromUV(Vector2 uv)

Converts UV coordinates (0–1) to latitude/longitude.

static Vector2 GetBillboardPointFromLatLon(Vector2 latlon)

Converts latitude/longitude to billboard coordinates.

static Rect GetBillboardRectFromLatLonRect(Rect latlonRect)

Converts a lat/lon rectangle to billboard coordinates.

static Rect GetUVRectFromLatLonRect(Rect latlonRect)

Converts a lat/lon rectangle to UV coordinates.

static Vector2 ConvertToTextureCoordinates(Vector3 localPos, int width, int height)

Converts local map position to texture pixel coordinates.

static Vector2 GetBillboardPosFromSpherePoint(Vector3 p)

Converts a sphere point to billboard position.

static void GetLatLonFromSpherePoint(Vector3 p, out float lat, out float lon)

Converts a sphere point to latitude and longitude.

Viewport & Rendering

Camera mainCamera

Gets or sets the camera used for map rendering. Changing this triggers a viewport refresh.

Transform sun

Reference to a directional light or sun Transform for lighting effects.

GameObject renderViewport

Target GameObject used to display the map. Defaults to the map itself.

Rect renderViewportScreenRect

Normalized screen rectangle (0–1) defining where the map viewport is rendered.

bool renderViewPortScreenOverlay

When true, the map viewport is rendered as a screen overlay.

FilterMode renderViewportFilterMode

Texture filter mode for the render viewport (Point, Bilinear, or Trilinear).

Camera currentCamera read-only

Returns the camera currently used for rendering (may differ from mainCamera when using a viewport).

static float mapWidth read-only

Width of the map in world units. Defaults to 200.

static float mapHeight read-only

Height of the map in world units. Defaults to 100.

IInputProxy input

Reference to the input proxy used for pointer and keyboard input.

WorldMap2D_Editor editor read-only

Returns the Editor sub-component (creates it if needed). Used for runtime map editing.

bool isDirty

Internal flag indicating unsaved changes. Set automatically by property setters.

Earth & Map Appearance

bool showEarth

Toggle visibility of the Earth/map background.

EARTH_STYLE earthStyle

Visual style for the map background (Natural, Alternate1–3, SolidColor, NaturalHighRes, NaturalScenic, etc.).

Color earthColor

Background color when earthStyle is set to SolidColor.

Interaction Properties

bool allowUserDrag { get; set; }

Allow the user to drag/pan the map.

bool allowUserZoom { get; set; }

Allow the user to zoom in/out.

bool respectOtherUI { get; set; }

Prevents map interaction when the pointer is over a UI element.

float zoomMaxDistance { get; set; }

Maximum zoom-out distance.

float zoomMinDistance { get; set; }

Maximum zoom-in distance (minimum camera distance).

bool mouseIsOver

True when the mouse cursor is over the map.

bool allowUserKeys

Allow keyboard-based map navigation.

bool dragFlipDirection

Inverts the drag direction for map panning.

bool dragConstantSpeed

When true, drag panning moves at constant speed regardless of zoom level.

bool allowScrollOnScreenEdges

Enables map scrolling when the cursor reaches the screen edges.

int screenEdgeThickness

Thickness in pixels of the screen-edge scroll trigger zone.

bool centerOnRightClick

When true, right-clicking centers the map on the clicked position.

LayerMask blockingMask

Layer mask determining which UI elements block map interaction.

bool zoomOnCursorPosition

When true, zooming is centered on the cursor position rather than the map center.

bool invertZoomDirection

Inverts the zoom scroll direction.

bool zoomConstantSpeed

When true, zooming moves at constant speed regardless of current zoom level.

float mouseWheelSensitivity

Sensitivity of the mouse wheel for zooming (0.1–3).

float mouseDragSensitivity

Sensitivity of mouse drag for panning (0.1–3).

int mouseDragThreshold

Minimum pixel distance before a drag is registered.

bool staticCamera

When true, the map moves instead of the camera during drag and zoom operations.

PointerSource pointerSource

Source of pointer input: Mouse, ViewCenter, or Custom.

Mount Points

List<MountPoint> mountPoints

List of all mount points on the map.

void HideMountPointHighlights()

Resets all mount point markers to their default color.

void ToggleMountPointHighlight(int mountPointIndex, Color color, bool highlighted)

Highlights or un-highlights a mount point marker.

string[] GetMountPointNames()

Returns a sorted array of all mount point names.

string[] GetMountPointNames(int countryIndex)

Returns mount point names filtered by country.

string[] GetMountPointNames(int countryIndex, int provinceIndex)

Returns mount point names filtered by country and province.

int GetMountPointIndex(int countryIndex, int provinceIndex, string mountPointName)

Returns the index of a mount point. Pass -1 to countryIndex or provinceIndex to ignore those filters.

bool GetMountPointIndex(Ray ray, out int mountPointIndex)

Returns the mount point index at a screen ray position.

int GetMountPointNearPoint(Vector2 localPoint)

Returns the index of the mount point nearest to a map position.

int GetMountPointNearPoint(Vector2 localPoint, float separation)

Returns the nearest mount point within a given distance threshold.

void MountPointsDeleteFromSameContinent(string continentName)

Deletes all mount points belonging to countries in the specified continent.

void MountPointAdd(Vector2 location, string name, int countryIndex, int provinceIndex, int type)

Adds a new mount point at the specified location.

List<MountPoint> GetMountPoints(Region region)

Returns all mount points contained in a given region.

Sub-Components

WorldMap2D_Calculator calc { get; }

Returns the Calculator component (enables and creates it if needed).

WorldMap2D_Ticker ticker { get; }

Returns the Ticker component for scrolling text overlays.

WorldMap2D_Decorator decorator { get; }

Returns the Decorator component for placing objects on countries/provinces.

Utility Methods

void ReloadData()

Reloads all map data (frontiers, cities, provinces, mount points) from data files and redraws the map.

void Redraw()

Forces a complete redraw of all map layers (frontiers, cities, provinces, grid, labels).

bool GetLocalHitFromScreenPos(Vector3 screenPos, out Vector3 localPoint)

Converts a screen position to local map coordinates. Handles viewports.

bool GetLocalHitFromRay(Ray ray, out Vector3 localPoint)

Converts a world ray to local map coordinates. Handles viewports.

GameObject GetOverlayLayer(bool createIfNotExists)

Returns the overlay layer used for labels and custom overlays. Creates it if requested.

Code Examples

using UnityEngine;
using WPMF;

public class MapExample : MonoBehaviour {
    WorldMap2D map;

    void Start() {
        map = WorldMap2D.instance;

        // Subscribe to country click
        map.OnCountryClick += (countryIndex, regionIndex) => {
            Debug.Log("Clicked: " + map.countries[countryIndex].name);
        };

        // Fly to Spain and color it
        int spain = map.GetCountryIndex("Spain");
        if (spain >= 0) {
            map.FlyToCountry(spain, 2f, 0.1f);
            map.ToggleCountrySurface(spain, true, Color.red);
        }

        // Convert lat/lon to map position
        Vector2 madrid = Conversion.GetLocalPositionFromLatLon(40.4168f, -3.7038f);
        Debug.Log("Madrid position: " + madrid);
    }
}
Was this page helpful?
X Tutup