Answer the question
In order to leave comments, you need to log in
How to save game data for Android/IOS?
The game on Unity is driving a car in an open world, you can also transport passengers in the game, thereby earning money, there is tuning for cars. And now you need to save this data about purchased cars, purchased improvements. Of course, the purchase logic itself is somehow implemented, you just need to save these purchases, the number of coins, etc. I have already familiarized myself with two ways to save, the first way is through the use of the "PlayerPrefs" class, but this class does not save data type "bool", which have a primary role in the project, this option disappears (of course, if you do not offer to bypass the use of "bool", replacing it with "int" and assigning "0" or "1" to such data, but is such a reliable way?), the second option is "serialization", but the author of the lesson emphasized that serialization can be problematic with OS "Android" and "IOS" ... How to be then? It is desirable for me not a cumbersome way, but to keep all of the above.
Answer the question
In order to leave comments, you need to log in
Take all the data you need to save, put it in json/xml, and save it in PlayerPrefs as a string.
For optimization, you can detail by logical elements.
Create your own class/list structure etc to save the world from regular C# classes with public properties and public empty constructors. Store all your data in this structure and serialize to a file. For serialization, select any of the provided assets for binary formats and feed your classes/lists to it:
https://assetstore.unity.com/search?q=bson or
https://assetstore.unity.com/search?q=messagepack
Although in fact, JSON is more compact in places than BSON, and it can also be used. JSON.NET is not bad. If you need a multiplatform, then JSON & MessagePack works everywhere.
In order to select a folder for saving, you can use the following code:
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN || UNITY_WP8
var appData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
#else
var appData = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
#endif
var serializer = new JsonSerializer();
serializer.Serialize(writer, myData)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question