Changing Serialization Method
Save Game Pro provides two serialization method for serializing the data, each one has it’s own advantages and disadvantages:
- JSON Serialization
- Binary Serialization
The JSON serialization is human-readable and could be modified by a human, but the Binary serialization is not human-readable and cannot be modified by a human, so, you should use each them at their own right place.
Each serialization method has it’s own use cases, the JSON serialization Use Cases are:
- Serializing Settings and allow the user to be able to modify them from outside of the game.
- Serializing Player information such as name, title, display name, … but not the player data.
- Serializing Localization strings and translations
- and much more …
and the Binary serialization Use Cases are:
- Serializing Game Data such as scores, health, unlocked levels, …
- Serializing Player data and stats
- Serializing the Progress, such as completed levels, unlocked levels, current player stats such as weapons and skills, …
- and much more…
The Above Use Cases are just some examples to help you choose the right serialization method at the right place.
Now let us teach you how to change the serialization method in the Save Game Pro, you have two choices, you can change the serialization method Globally, or change it Locally.
Changing Serialization method Globally:
// Changing to JSON serialization
SaveGameSettings settings = SaveGame.DefaultSettings;
settings.Formatter = new BayatGames.SaveGamePro.Serialization.Formatters.Json.JsonFormatter ();
SaveGame.DefaultSettings = settings;
// Changing to Binary serialization
SaveGameSettings settings = SaveGame.DefaultSettings;
settings.Formatter = new BayatGames.SaveGamePro.Serialization.Formatters.Binary.BinaryFormatter ();
SaveGame.DefaultSettings = settings;
Or, changing the Serialization method Locally:
// Changing to JSON serialization
SaveGameSettings settings = SaveGame.DefaultSettings;
settings.Formatter = new BayatGames.SaveGamePro.Serialization.Formatters.Json.JsonFormatter ();
SaveGame.Save ( "example", "Example", settings );
// Changing to Binary serialization
SaveGameSettings settings = SaveGame.DefaultSettings;
settings.Formatter = new BayatGames.SaveGamePro.Serialization.Formatters.Binary.BinaryFormatter ();
SaveGame.Save ( "example", "Example", settings );
Please note, you should use same Serialization method for both Saving and Loading, otherwise, the data serialization and deserialization will fail.