World Map 2D Edition · Scripting Support (C#)
WorldMap2D component (namespace WPMF). Access via WorldMap2D.instance.
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.
The main data types you'll interact with:
Represents a country. Key fields: name, continent, center (Vector2), regions (List<Region>), provinces (Province[]), hidden, customLabel, labelColor, labelVisible, labelRotation.
Represents a province/state. Key fields: name, countryIndex, center (Vector2), regions (List<Region>), mainRegionIndex.
Represents a city. Fields: name, province, countryIndex, unity2DLocation (Vector2), population, cityClass (CITY_CLASS enum), isVisible.
A custom point of interest. Fields: name, type (int), countryIndex, provinceIndex, unity2DLocation (Vector2), customTags (Dictionary<string, string>).
A contiguous area of a country or province. Key fields: points (Vector3[]), center (Vector2), rect2D (Rect), neighbours (List<Region>), customMaterial.
CITY = 1, REGION_CAPITAL = 2, COUNTRY_CAPITAL = 4
Low = 0, High = 1
Natural, Alternate1, Alternate2, Alternate3, SolidColor, NaturalHighRes, NaturalScenic, NaturalHighRes16K, NaturalScenic16K
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 / OnProvinceClickProvince 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 OnCityClickCity interaction events.
event OnSimpleMapEvent OnDragStart() / OnDragEndFired when the user starts or stops dragging the map.
event OnClickEvent OnClick(Vector2 localPoint)General map click event.
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[] countriesArray 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-onlyReturns the currently highlighted country region object, or null if none.
int countryRegionHighlightedIndex read-onlyReturns the region index of the currently highlighted country (-1 if none).
int countryRegionLastClicked read-onlyReturns the region index of the last clicked country.
bool highlightAllCountryRegionsWhen true, highlighting a country highlights all of its regions, not just the one under the pointer.
float countryHighlightMaxScreenAreaSizeMaximum screen area ratio (0–1) a highlighted country can fill. Prevents large countries from flooding the screen with color.
bool frontiersThinLinesWhen true, frontier lines remain thin even when zoomed in.
Color frontiersColorOuterOuter color for country frontier lines (creates a border glow effect).
bool showOutlineToggle thicker outline visibility around country frontiers.
Color outlineColorColor of the thicker country outline.
Color fillColorFill color used when the pointer hovers over a country region.
FRONTIERS_DETAIL frontiersDetailLevel of detail for country frontiers (Low or High).
float countryLabelsAbsoluteMinimumSizeAbsolute minimum size for country labels. Labels smaller than this value will not be rendered.
bool showLabelsShadowDraws a shadow beneath country labels. Set the shadow color with countryLabelsShadowColor.
Color countryLabelsShadowColorColor of the shadow drawn beneath country labels.
Font countryLabelsFontGets or sets the TrueType font used for country labels.
bool countryLabelSpreadWhen true, country names include extra spacing to spread across large country surfaces.
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.
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[] 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-onlyReturns the province currently under the pointer, or null if none.
int provinceHighlightedIndex read-onlyReturns the index of the currently highlighted province (-1 if none).
Region provinceRegionHighlighted read-onlyReturns the currently highlighted province region object.
int provinceRegionHighlightedIndex read-onlyReturns the region index of the currently highlighted province.
int provinceLastClicked read-onlyReturns the index of the last clicked province.
int provinceRegionLastClicked read-onlyReturns the region index of the last clicked province.
bool enableProvinceHighlightEnable or disable province highlighting on hover.
bool drawAllProvincesWhen true, draws province borders for all countries, not just the selected one.
Color provincesFillColorFill color used when the pointer hovers over a province region.
Color provincesColorColor 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.
List<City> citiesList 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-onlyReturns the city currently under the pointer, or null if none.
int cityHighlightedIndex read-onlyReturns the index of the currently highlighted city (-1 if none).
int cityLastClicked read-onlyReturns the index of the last clicked city.
CITY_CLASS_FILTER cityClassFilterFilters which classes of cities are displayed (Any, RegionCapitals, CountryCapitals, RegionAndCountryCapitals).
Color citiesColorGlobal color for normal city markers.
Color citiesRegionCapitalColorGlobal color for region capital markers.
Color citiesCountryCapitalColorGlobal color for country capital markers.
float cityIconSizeSize of the city marker icons.
float cityHitTestRadiusHit-test radius multiplier for city markers. Adjust when the map scale changes.
int minPopulationMinimum population threshold for displaying cities. Cities below this value are hidden.
int cityClassAlwaysShowBit 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-onlyNumber 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.
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 fitWindowWidthWhen true, the map scales to fill the window width.
bool fitWindowHeightWhen true, the map scales to fill the window height.
Vector2 flyToScreenCenterScreen 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.
bool showCursorToggle visibility of the crosshair cursor lines on the map.
Color cursorColorColor of the cursor crosshair lines.
bool cursorFollowMouseWhen true, the cursor lines follow the mouse position over the map.
Vector3 cursorLocationGets or sets the cursor crosshair position in map local coordinates.
bool showLatitudeLinesToggle visibility of latitude grid lines.
int latitudeSteppingSpacing in degrees between latitude lines (5–45).
bool showLongitudeLinesToggle visibility of longitude grid lines.
int longitudeSteppingSpacing in degrees between longitude lines (5–45).
Color gridLinesColorColor of the latitude and longitude grid 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.
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.
Camera mainCameraGets or sets the camera used for map rendering. Changing this triggers a viewport refresh.
Transform sunReference to a directional light or sun Transform for lighting effects.
GameObject renderViewportTarget GameObject used to display the map. Defaults to the map itself.
Rect renderViewportScreenRectNormalized screen rectangle (0–1) defining where the map viewport is rendered.
bool renderViewPortScreenOverlayWhen true, the map viewport is rendered as a screen overlay.
FilterMode renderViewportFilterModeTexture filter mode for the render viewport (Point, Bilinear, or Trilinear).
Camera currentCamera read-onlyReturns the camera currently used for rendering (may differ from mainCamera when using a viewport).
static float mapWidth read-onlyWidth of the map in world units. Defaults to 200.
static float mapHeight read-onlyHeight of the map in world units. Defaults to 100.
IInputProxy inputReference to the input proxy used for pointer and keyboard input.
WorldMap2D_Editor editor read-onlyReturns the Editor sub-component (creates it if needed). Used for runtime map editing.
bool isDirtyInternal flag indicating unsaved changes. Set automatically by property setters.
bool showEarthToggle visibility of the Earth/map background.
EARTH_STYLE earthStyleVisual style for the map background (Natural, Alternate1–3, SolidColor, NaturalHighRes, NaturalScenic, etc.).
Color earthColorBackground color when earthStyle is set to SolidColor.
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 mouseIsOverTrue when the mouse cursor is over the map.
bool allowUserKeysAllow keyboard-based map navigation.
bool dragFlipDirectionInverts the drag direction for map panning.
bool dragConstantSpeedWhen true, drag panning moves at constant speed regardless of zoom level.
bool allowScrollOnScreenEdgesEnables map scrolling when the cursor reaches the screen edges.
int screenEdgeThicknessThickness in pixels of the screen-edge scroll trigger zone.
bool centerOnRightClickWhen true, right-clicking centers the map on the clicked position.
LayerMask blockingMaskLayer mask determining which UI elements block map interaction.
bool zoomOnCursorPositionWhen true, zooming is centered on the cursor position rather than the map center.
bool invertZoomDirectionInverts the zoom scroll direction.
bool zoomConstantSpeedWhen true, zooming moves at constant speed regardless of current zoom level.
float mouseWheelSensitivitySensitivity of the mouse wheel for zooming (0.1–3).
float mouseDragSensitivitySensitivity of mouse drag for panning (0.1–3).
int mouseDragThresholdMinimum pixel distance before a drag is registered.
bool staticCameraWhen true, the map moves instead of the camera during drag and zoom operations.
PointerSource pointerSourceSource of pointer input: Mouse, ViewCenter, or Custom.
List<MountPoint> mountPointsList 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.
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.
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.
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);
}
}
Help us improve this documentation page.