Table of Contents
See Demo Scene 104
Suppose your game changes geodata at runtime. It could change country name, or population, or the relationship between a province and its country, or even change frontiers of countries and provinces. Then you want to save the modified data so the player can resume the game in the future, how to do that?
Well, WMSK does not provide you a persistence layer, like a local database, but it provides you the required functions so you can get and set the state of the entities (countries, provinces, cities and mount points) in a formatted string so you can store that text information wherever you want and reload it in a later moment.
The functions are:
GetCountryGeoData(): returns a string containing the countries information, including the frontiers data. SetCountryGeoData(string): loads the countries information, including frontiers data, from the given string.
Optional functions (only useful if you are adding custom attributes to countries):
GetCountriesAttributes(): returns a string in jSON format containing any country attribute (the contents of the .attrib field for each country). SetCountriesAttributes(string): loads the countries attributes from the given string.
Provinces, Cities and MountPoints
Similar functions are available for provinces, cities and mountpoints (GetProvincesGeoData(), …).
Where can I store the geodata?
GetCountryGeoData(), GetProvinceGeoData(), … all returns a string with the required information. You can store this string in:
- A local text file in the Application data folder. Example: System.IO.
- A local database like SQLite.
- A remote database using a webservice.
For example, to save the country information to a local text file you could do:
string s = map.GetCountryGeoData(); System.IO.File.WriteAllText(Application.persistentDataPath + "/myCountries", s);
And to retrieve the country geodata in a future session you would do:
string s = System.IO.File.ReadAllText(Application.persistentDataPath + "/myCountries"); map.SetCountryGeoData(s);