Countries API
advanced scriptingWorld Map Strategy Kit · Scripting Support (C#)
WMSK (namespace WorldMapStrategyKit)
Countries API
Methods and properties for working with countries on the world map.
Properties
Country[] countriesArray of all countries on the map.
Country countryHighlighted { get; }The country currently under the pointer (null if none).
int countryHighlightedIndex { get; }Index of the highlighted country (-1 if none).
int countryLastClicked { get; }Index of the last clicked country.
bool enableCountryHighlight { get; set; }Enable or disable country highlighting on hover.
bool showFrontiers { get; set; }Show or hide country borders (frontiers).
bool showCountryNames { get; set; }Show or hide country name labels.
Color frontierColor { get; set; }Color of country borders.
Color fillColor { get; set; }Default fill color for country surfaces.
enum FRONTIERS_DETAILLevel of detail for country frontiers.
enum OUTLINE_DETAILLevel of detail for country outlines.
enum TEXT_ENGINEText engine used for country labels (Unity or TextMesh Pro).
enum TEXT_RENDERING_MODEText rendering mode for labels.
Region countryRegionHighlightedReturns the currently highlighted country region.
int countryRegionHighlightedIndexReturns currently highlighted region of the country.
int countryRegionLastClickedReturns the last clicked country region index.
GameObject countryRegionHighlightedShapeGets the country region's highlighted shape.
int countryLastOverReturns the last hovered country.
int countryRegionLastOverReturns the last hovered country region index.
bool highlightAllCountryRegionsWhen enabled, all regions of a country are highlighted on hover (not just the main region).
bool combineCountrySurfacesWhen enabled, surfaces of all regions of a country are combined into a single mesh.
bool highlightCountryRecolorWhen enabled, recolors already-colored countries on highlight instead of overlaying.
bool highlightCountryKeepTextureWhen enabled, keeps the existing texture on a country when highlighting.
float highlightMaxScreenAreaSizeDefines the maximum area of a highlighted country or province. To prevent filling the whole screen with the highlight color, you can reduce this value and if the highlighted screen area size is greater than this factor (1=whole screen) the country won't be filled (it will behave as selected though)
bool frontiersCoastlinesInclude coasts in frontier lines
Color frontiersColorColor of country frontiers (borders).
Color frontiersColorOuterOuter color for double-line country frontiers.
bool thickerFrontiersEnable alternate frontiers shader.
bool frontiersDynamicWidthEnable dynamic width of country frontiers when zooming in/out
float frontiersWidthWidth of country frontier lines.
int frontiersMaxPixelWidthMaximum pixel width for country frontier lines.
bool showOutlineToggle frontiers thicker outline visibility.
Color outlineColorColor of the country outline.
OUTLINE_DETAIL outlineDetailQuality level for outline.
Texture2D outlineTextureTexture for the outline when outlineDetail is set to Textured.
float outlineWidthWidth of the country outline.
float outlineTilingScaleTiling scale for textured country outlines.
float outlineAnimationSpeedAnimation speed for textured country outlines (0 = static).
FRONTIERS_DETAIL frontiersDetailLevel of geometric detail for frontier lines.
TEXT_ENGINE countryLabelsTextEngineText engine for country labels (Unity or TextMesh Pro).
TEXT_RENDERING_MODE countryLabelsRenderingModeRendering mode for country labels.
bool countryLabelsAlwaysOnTopWhen enabled, country labels render on top of other map elements.
bool countryLabelsUseMapCurvatureWhen enabled, labels follow the curvature of the map.
float countryLabelsElevationElevation offset for country labels above the map surface.
float countryLabelsLengthMaximum length ratio for country labels relative to country width.
float countryLabelsHorizontalityBias toward horizontal placement for country labels (0 = auto, 1 = fully horizontal).
float countryLabelsCurvatureCurvature amount for country labels.
float countryLabelsAbsoluteMinimumSizeAbsolute minimum font size for country labels (labels smaller than this are hidden).
float countryLabelsSizeRelative size multiplier for country labels.
bool countryLabelsEnableAutomaticFadeAutomatic fading of country labels depending on camera distance and label screen size
float countryLabelsAutoFadeMaxHeightMax height of a label relative to screen height (0..1) at which fade out starts
float countryLabelsAutoFadeMaxHeightFallOffFall off for fade labels when height is greater than min height
float countryLabelsAutoFadeMinHeightMin height of a label relative to screen height (0..1) at which fade out starts
float countryLabelsAutoFadeMinHeightFallOffFall off for fade labels when height is less than min height
bool showLabelsShadowDraws a shadow under map labels. Specify the color using labelsShadowColor.
Color countryLabelsColorColor for map labels.
Color countryLabelsShadowColorColor for map labels.
Vector2 countryLabelsShadowOffsetShadow offset for country labels
bool countryLabelsUseCentroidUse the country centroid to position the label, instead of the geometric center.
Font countryLabelsFontDefault Unity font for country labels
UnityEngine.Object countryLabelsFontTMProTextMesh Pro font asset for country labels.
Material countryLabelsFontTMProMaterialTextMesh Pro font material for country labels.
Color countryLabelsOutlineColorColor for the label outline. Only used with TextMesh Pro text engine.
float countryLabelsOutlineWidthWidth for the label outline. Only used with TextMesh Pro text engine.
string countryAttributeFilePath to the JSON file containing custom country attributes.
float labelsElevationLabels elevation for normal 2D flat mode
Query Methods
Country GetCountry(string countryName)Returns a Country object by name. Returns null if not found.
Country GetCountry(int countryIndex)Returns a Country object by index.
int GetCountryIndex(string countryName)Returns the country index by name. Returns -1 if not found.
int GetCountryIndex(Vector2 localPosition)Returns the country at a given map position (2D local coordinates).
string[] GetCountryNames(bool groupByContinent = false)Returns an array of all country names. If groupByContinent is true, names are prefixed with continent.
List<Country> CountryNeighbors(int countryIndex)Returns a list of neighboring countries (sharing a border).
City GetCountryCapital(string countryName)Returns the capital city of a country (the city with the highest population).
List<Country> GetVisibleCountries()Returns a list of countries currently visible in the viewport.
Country GetCountryRandom()Returns a random country from the map.
bool ValidCountryIndex(int countryIndex)Returns true if the countryIndex is valid (ie. within country array range)
bool ValidCountryRegionIndex(int countryIndex, int regionIndex)Returns true if the countryIndex and regionIndex are valid (ie. within country and country regions array range)
int GetCountryIndexByFIPS10_4(string fips)Returns the index of a country in the countries by its FIPS 10 4 code.
int GetCountryIndexByISO_A2(string iso_a2)Returns the index of a country in the countries by its ISO A-2 code.
int GetCountryIndexByISO_A3(string iso_a3)Returns the index of a country in the countries by its ISO A-3 code.
int GetCountryIndexByISO_N3(string iso_n3)Returns the index of a country in the countries by its ISO N-3 code.
int GetCountryRegionIndex(int countryIndex, Region region)Gets the index of the country region. The country region index. Country index. Region.
int GetCountryRegionIndex(Vector2 localPosition)Gets the region index of the country that contains the provided map coordinates. This will ignore hidden countries. The Region index or -1 if no region found. Map coordinates in the range of (-0.5 .. 0.5)
Vector2 GetCountryCenter(int countryIndex)Returns the center of a country
Vector2 GetCountryCentroid(int countryIndex)Returns the centroid of a country
Vector2 GetCountryCentroid(Country country)Returns the centroid of a country
Region GetCountryRegion(Vector2 localPosition)Gets the region of the country that contains the provided map coordinates. This will ignore hidden countries. The Region object. Map coordinates in the range of (-0.5 .. 0.5)
List CountryNeighborsOfMainRegion(int countryIndex)Get neighbors of the main region of a country
List CountryNeighborsOfCurrentRegion()Get neighbors of the currently selected region
List CountryNeighborsOfRegion(Region countryRegion)Get neighbors of a given country region
bool CountryIsNeighbor(int countryIndex, int otherCountryIndex)Returns true if two given countries are neighbors
void CountryMakeNeighbors(int countryIndex, int otherCountryIndex)Makes one country neighbor of another
List GetVisibleCountriesInWindowRect()Returns a list of countries that are visible inside the window rectangle (rect constraints)
float GetCountryRegionZoomExtents(int countryIndex)Returns the zoom level required to show the entire country region on screen The country zoom level of -1 if error. Country index.
float GetCountryRegionZoomExtents(int countryIndex, int regionIndex)Returns the zoom level required to show the entire country region on screen The country zoom level of -1 if error. Country index. Region index of the country.
float GetCountryZoomExtents(int countryIndex, bool onlyMainRegion)Returns the zoom level required to show the entire country (including all regions or only the main region) on screen The country zoom level of -1 if error. Country index. If set to true, only the main region will be considered. A value of false (default) ensures entire country including islands fits into the screen.>
List GetCountries(AttribPredicate predicate)Returns a list of countries whose attributes matches predicate
List GetCountriesOverlap(Region region)Gets a list of countries that overlap with a given region
List GetCountryRegionsOverlap(Region region)Gets a list of country regions that overlap with a given region
List GetCountryCoastalPoints(int countryIndex, float minDistance, bool includeAllRegions)Returns the list of costal positions of a given country
List GetCountryCoastalPoints(int countryIndex, int regionIndex, float minDistance)Returns the list of costal positions of a given country
List GetCountryFrontierPoints(int countryIndex1, int countryIndex2, int extraWidth)Returns a list of common frontier points between two countries. Use extraWidth to widen the points, useful when using the result to block pass in pathfinding
Vector3[] GetCountryFrontierPoints(int countryIndex, bool worldSpace)Returns the points for the given country region. Optionally in world space coordinates (normal map, not viewport).
Vector3[] GetCountryFrontierPoints(int countryIndex, int regionIndex, bool worldSpace)Returns the points for the given country region. Optionally in world space coordinates (normal map, not viewport).
Manipulation Methods
bool CountryRename(string oldName, string newName)Renames a country. Returns true if successful.
bool CountryDelete(int countryIndex, bool deleteDependencies = true, bool redraw = true)Deletes a country. If deleteDependencies is true, also removes its provinces, cities, and mount points.
bool CountryTransferProvinceRegion(int targetCountryIndex, Region provinceRegion, bool redraw = true)Transfers a province region to another country.
int CountryCreate(string countryName, string continentName)Creates a new country and returns its index.
void CountryRegionAdd(int countryIndex, List<Vector2> points)Adds a new region (polygon) to a country.
bool CountryDeleteProvinces(int countryIndex)Deletes all provinces from a country. true, if provinces where deleted, false otherwise.
void CountriesDeleteFromContinent(string continentName)Deletes all countries belonging to the specified continent.
int CountryAdd(Country country)Adds a new country which has been properly initialized. Used by the Map Editor. Name must be unique. country index if country was added, -1 otherwise.
int CountryCreateProvincesPool(string countryName, bool removeAllOtherCountries)Creates a special hidden country that acts as a pool for all provinces in the map. You can then create new countries from a single province from this pool using ProvinceToCountry function Or attach a province from the pool to a new country using CountryTransferProvince function The country index of the new country that acts as the province pool. A name for this special country (eg: "Pool").
bool CountrySanitize(int countryIndex, int minimumPoints, bool refresh)Checks quality of country's polygon points. Useful before using polygon clipping operations. true, if country was sanitized (there was any change), false if country data has not changed.
bool CountryTransferCountry(int countryIndex, int sourceCountryIndex, bool redraw, bool mergeRegions, bool deleteSourceCountryIfEmpty)Makes countryIndex absorb another country. All regions are transfered to target country. This function is quite slow with high definition frontiers. Country index of the conquering country. Source country of the loosing country. Merge resulting regions into a single region (if they're overlapping or intersect). If false, source country will be added as new region without any merging (faster). After the country is absorbed, remove the source country from the countries array.
bool CountryTransferCountryRegion(int countryIndex, Region sourceCountryRegion, bool redraw, bool mergeRegions, bool deleteSourceCountryIfEmpty)Makes countryIndex absorb another country providing any of its regions. All regions are transfered to target country. This function is quite slow with high definition frontiers. Country index of the conquering country. Source region of the loosing country. Merge resulting regions into a single region (if they're overlapping or intersect). If false, source country will be added as new region without any merging (faster). After the country is absorbed, remove the source country from the countries array.
bool CountryTransferProvince(int targetCountryIndex, int provinceIndex, bool redraw)Changes province's owner to specified country and modifies frontiers/borders.
bool CountryTransferProvinces(int targetCountryIndex, List provinces, bool redraw, bool deleteSourceCountryIfEmpty)Changes provinces' owner to specified country and modifies frontiers/borders. If a source country is left without any province, remove it from the countries array
bool CountrySetProvinces(int countryIndex, List provinces, bool mergeRegions, bool updateCities, bool updateMountPoints)Sets the provinces for an existing country. The country regions will be updated to reflect the regions of the new provinces. If true, adjacent regions will be merged (default).
bool CountryAddProvince(int countryIndex, Province province, bool mergeRegions, bool updateCities, bool updateMountPoints)Adds a province to an existing country, updating country regions accordingly.
bool CountryAddProvinces(int countryIndex, List provinces, bool mergeRegions, bool updateCities, bool updateMountPoints)Add provinces to an existing country. The country regions will be updated to reflect the regions of the new provinces. Please note that if the provinces currently belong to another country, that other country won't be updated. Call CountrySetProvinces or CountryRemoveProvinces on the other country as well. If true, adjacent regions will be merged (default).
bool CountryRemoveProvince(int countryIndex, Province province, bool mergeRegions)Remove a province from an existing country. If true, adjacent regions will be merged (default).
bool CountryRemoveProvinces(int countryIndex, List provincesToRemove, bool mergeRegions)Remove provinces from an existing country. The country regions will be updated to reflect the regions of the new provinces. If true, adjacent regions will be merged (default).
bool CountryTransferCell(int countryIndex, int cellIndex, bool redraw)Makes countryIndex absorb an hexagonal portion of the map. If that portion belong to another country, it will be substracted from that country as well. This function is quite slow with high definition frontiers. Country index of the conquering country. Index of the cell to add to the country.
bool CountryRemoveCell(int countryIndex, int cellIndex, bool redraw)Removes a cell from a country. Country index. Index of the cell to remove from the country.
Surface & Effects
GameObject ToggleCountryMainRegionSurface(int countryIndex, bool visible, Color color)Toggles the surface of a country's main region (largest polygon). Returns the surface GameObject. Also supports texture, scale, offset, and rotation parameters in overloads.
GameObject ToggleCountryRegionSurface(int countryIndex, int regionIndex, bool visible, Color color)Toggles a specific region surface by index.
GameObject ToggleCountryOutline(int countryIndex, bool visible, Color outlineColor)Toggles a custom outline for a country. Supports border texture, width, tint, tiling, and animation speed in overloads.
void BlinkCountry(int countryIndex, Color color1, Color color2, float duration, float blinkingSpeed)Applies a blinking animation to a country surface, alternating between two colors.
void HideCountrySurface(int countryIndex)Hides all surfaces for a country.
void HideCountrySurfaces()Hides all country surfaces on the entire map.
void SetCountryColoredRegions(int countryIndex, Color color)Colors all regions of a country with a single color.
bool ToggleCountrySurface(string name, bool visible, Color color)Colorize all regions of specified country by name. Returns false if not found.
bool ToggleCountrySurface(int countryIndex, bool visible, Color color)Colorize all regions of specified country by index in the countries collection.
bool ToggleCountrySurface(int countryIndex, bool visible, Texture2D texture, bool applyTextureToAllRegions)Colorize all regions of specified country and assings a texture.
bool ToggleCountrySurface(int countryIndex, bool visible, Color color, Texture2D texture, bool applyTextureToAllRegions)Colorize all regions of specified country and assings a color and texture.
bool ToggleCountrySurface(int countryIndex, bool visible, Color color, Texture2D texture, Vector2 textureScale, Vector2 textureOffset, float textureRotation, bool applyTextureToAllRegions)Colorize all regions of specified country and assings a texture. Country index. If set to true visible. Color. Texture. Texture scale. Texture offset. Texture rotation. If set to true the texture will be applied to all regions, otherwise only the main region will get the texture and the remaining regions will get the color.
void ToggleContinentSurface(string continentName, bool visible, Color color)Iterates for the countries list and colorizes those belonging to specified continent name.
void HideContinentSurface(string continentName)Uncolorize/hide specified countries beloning to a continent.
GameObject ToggleCountryRegionSurfaceHighlight(int countryIndex, int regionIndex, Color color, bool drawOutline)Highlights the country region specified. Internally used by the Editor component, but you can use it as well to temporarily mark a country region. Pass true only if you're sure you want to force refresh the geometry of the highlight (for instance, if the frontiers data has changed). If you're unsure, pass false.
GameObject ToggleCountryMainRegionOutline(int countryIndex, bool visible, Texture2D borderTexure, float borderWidth, Color tintColor), float textureTiling, float animationSpeed)Draws an outline around the main region of a country The country region outline.
GameObject ToggleCountryRegionOutline(int countryIndex, int regionIndex, bool visible, Texture2D borderTexure, float borderWidth, Color tintColor), float textureTiling, float animationSpeed)Draws an outline around a region The country region outline. Country index.
void HideCountryRegionSurface(int countryIndex, int regionIndex)Uncolorize/hide specified country by index in the countries collection.
GameObject GetCountryRegionSurfaceGameObject(string countryName, int regionIndex, bool forceCreation)Returns the colored surface (game object) of a country. If it has not been colored yet, it will optionally create it.
GameObject GetCountryRegionSurfaceGameObject(int countryIndex, int regionIndex, bool forceCreation)Returns the colored surface (game object) of a country. If it has not been colored yet, it will optionally create it.
GameObject GetCountryMainRegionSurfaceGameObject(string countryName, bool forceCreation)Returns the colored surface (game object) of the main region of a country. If it has not been colored yet, it will optionally create it.
GameObject GetCountryMainRegionSurfaceGameObject(int countryIndex, bool forceCreation)Returns the colored surface (game object) of the main region of a country. If it has not been colored yet, it will optionally create it.
Navigation
bool FlyToCountry(string name)Starts navigation to target country. Returns false if country is not found.
bool FlyToCountry(string name, float duration)Starts navigation to target country. with specified duration, ignoring NavigationTime property. Set duration to zero to go instantly. Returns false if country is not found.
bool FlyToCountry(string name, float duration, float zoomLevel)Starts navigation to target country. with specified duration and zoom level, ignoring NavigationTime property. Set duration to zero to go instantly. Returns false if country is not found.
void FlyToCountry(int countryIndex)Starts navigation to target country by index in the countries collection. Returns false if country is not found.
void FlyToCountry(int countryIndex, float duration)Starts navigating to target country by index in the countries collection with specified duration, ignoring NavigationTime property. Set duration to zero to go instantly.
void FlyToCountry(int countryIndex, float duration, float zoomLevel)Starts navigating to target country by index in the countries collection with specified duration, ignoring NavigationTime property. Set duration to zero to go instantly.
Data Import & Export
void SetCountriesGeodata(string s)Imports country geographic data from a packed string (previously exported with GetCountriesGeodata).
string GetCountriesGeodata()Exports the geographic data in packed string format.
byte[] GetCountriesGeodataBinary()Exports the geographic data in binary format.
void SetCountriesGeodataBinary(byte[] data)Imports country geographic data from binary format (previously exported with GetCountriesGeodataBinary).
string GetCountriesAttributes(bool prettyPrint)Gets XML attributes of all countries in jSON format.
string GetCountriesAttributes(List countries, bool prettyPrint)Gets XML attributes of provided countries in jSON format.
void SetCountriesAttributes(string jSON)Sets countries attributes from a jSON formatted string.
string GetCountriesDataJSON(bool prettyPrint)Returns country data (geodata and any attributes) in jSON format.
void SetCountriesDataJSON(string json)Sets country data (geodata and any attributes) in jSON format.
Suggest an improvement
Help us improve this documentation page.