skip to Main Content

Scripting Support (C#)

You can instantiate the prefab “WorldMap2D“ or add it to the scene from the Editor. Once the prefab is in the scene, you can access the functionality from code through the static instance property:

Using WPMF;

WorldMap2D map;

void Start () {
map = WorldMap2D.instance;

(Note that you can have more WorldMap2D instances in the same scene. In this case, the instance property will returns the same object. To use the API on a specific instance, you can get the WorldMap2D component of the GameObject).

Most of the public API and properties are located in WorldMap2D script inside Scripts/Core folder. Below is a list of them:

Public Properties & Methods

Country related

map.countries: the array of Country objects. Note that the number and indexes of countries varies between the low and high-definition geodata files (reloaded when you change the frontiersQuality property in the inspector or in the API).

map.GetCountryIndex(name): returns the index of the country in the array.

map.GetCountryIndex(ray, out countryIndex, out regionIndex): find the country pointed by the ray.

map.GetCountryNames(groupByContinent): returns an array with the country names, optionally grouped by continent.

map.countryHighlighted: returns the Country object for the country under the mouse cursor (or null).

map.countryHighlightedIndex: returns the index of country under the mouse cursor (or null if none).

map.countryRegionHighlighted: returns the Region object for the highlighted country (or null). Note that many contries have more than one region. The field mainRegionIndex of the Country object specified which region is bigger (usually the main body, being the rest islands or foreign regions).

map.countryRegionHIghlightedIndex: returns the index of the region of currently highlighted country for the regions field of country object.

map.countryLastClickedIndex: returns the index of last country clicked.

map.enableCountryHighlight: set it to true to allow countries to be highlighted when mouse pass over them.

map.fillColor: color for the highlight of countries.

map.showCountryNames: enables/disables country labeling on the map.

map.showOutline: draws a border around countries highlightes or colored.

map.outlineColor: color of the outline.

map.showFrontiers: show/hide country frontiers. Same than inspector property.

map.frontiersColor: color for all frontiers.

map.RenameCountry(oldName, newName): allows to change the country’s name. Use this method instead of changing the name field of the country object.

map.BlinkCountry(country, color1, color2, duration, speed): makes the country specified toggle between color1 and color2 for duration in seconds and at speed rate.

map.FlyToCountry(name): start navigation at navigationTime speed to specified country. The list of country names can be obtained through the cities property.

map.FlyToCountry(index): same but specifying the country index in the countries list.

map.ToggleCountrySurface(name, visible, color): colorize one country with color provided or hide its surface (if visible = false).

map.ToggleCountrySurface(index, visible, color): same but passing the index of the country instead of the name.

map.ToggleCountryMainRegionSurface(index, visible, color, Texture2D texture): colorize and apply an optional texture to the main region of a country.

map.ToggleCountryRegionSurface(countryIndex, regionIndex, visible, color): same but only affects one single region of the country.

map.HideCountrySurface(countryIndex): un-colorize / hide specified country.

map.HideCountryRegionSurface(countryIndex): un-colorize / hide specified region of a country.

map.HideCountrySurfaces: un-colorize / hide all colorized countries (cancels ToggleCountrySurface).

Cities related

map.cities: return a List<City> of all cities records.

map.GetCityNames: return an array with the names of the cities.

map.cityHighlighted: returns the city under the mouse cursor (or null if none).

map.showCities: show/hide all cities. Same than inspector property.

map.minPopulation: the mínimum population amount for a city to appear on the map (in thousands). Set to zero to show all cities in the current catalog. Range: 0 .. 17000.

map.FlyToCity(name): start navigation at navigationTime speed to specified city. The list of city names can be obtained through the cities property.

map.FlyToCity(index): same but specifying the city index in the cities list.

Earth related

map.showEarth: show/hide the planet Earth. Same than inspector property.

map.earthColor: the currently color used in the Earth when style = SolidColor.

map.showLatitudeLines: draw latitude lines.

map.latitudeStepping: separation in degrees between each latitude line.

map.showLongitudeLines: draw longitude lines.

map.longitudeStepping: number of longitude lines.

map.gridLinesColor: color of latitude and longitude lines.

User interaction

map.mouseIsOver: returns true if mouse has entered the Earth’s sphere collider.

map.navigationTime: time in seconds to fly to the destination (see FlyTo methods).

map.allowUserDrag/map.allowUserZoom: enables/disables user interaction with the map.

map.mouseWheelSensibility: multiplying factor for the zoom in/out functionality.

map.mouseDragSensibility: multiplying factor for the drag functionality.

map.showCursor: enables the cursor over the map.

map.cursorFollowMouse: makes the cursor follow the map.

map.cursorLocation: current location of cursor in local coordinates (by default the sphere is size (1,1,1) so x/y/z can be in (-0.5,0.5) interval. Can be set and the cursor will move to that coordinate.

map.fitWindowWidth: makes the map occupy the width of the screen.

map.fitWindowHeight: makes the map occupy also the height of the screen.

map.CenterMap(): positions the map in front of the main camera.

map.FlyToLocation (x, y, z): same but specifying the location in local Unity spherical coordinates.

map.respectOtherUI: prevents map interactions while pointer is on UI (buttons, labels, …)

Labels related

map.showCountryNames: toggles countriy labels on/off.

map.countryLabelsSize: this is the relative size for labels. Controls how much the label can grow to fit the country area.

map.countryLabelsAbsoluteMinimumSize: minimum absolute size for all labels.

map.labelsQuality: specify the quality of the label rendering (Low, Medium, High).

map.showLabelsShadow: toggles label shadowing on/off.

map.countryLabelsColor: color for the country labels. Supports alpha.

map.countryLabelsShadowColor: color for the shadow of country labels. Also supports alpha.

map.countryLabelsFont: Font for the country labels.


map.ToggleContinentSurface(name, visible, color): colorize countries belonging to specified continent with color provided or hide its surface (if visible = false).

map.HideContinentSurface(name): uncolorize/hide countries belonging to the specified continent.

Back To Top