Save Manager

Save Manager

The Save Manager allows you to save the songs high score to disk. The high scores are saved on the Rhythm Timeline Asset scriptable object. scriptable objects values are stored during development even when changed at runtime. But values do not persist once the game is built. Therefore the values must be stored on disk such that they may be saved while playing on a release build on a device. The Save Manager converts the high score data of all songs into Json and then into binary. The binary data is then saved on disk as a save file. When loading, the save manager does the same in reverse.

Image

The Save Manager listens to an event on the Score Manager to know when a new high score was made to know when it should save to disk. You may also automatically load on start.

For Debugging purposes, there is an option to print a copy of the save file in a readable Json format.

Some context menu items are available when right-clicking the Save Manager Component (or when pressing the three dots on the top right of the component)

Image

  • Print Save Folder Path: This prints in the console, the path to the folder where the save file will be saved.
  • Reset All Song High Scores: Resets all the high scores for the songs that are referenced in the Rhythm Game Manager.
  • Save ALl Songs To File: Save all songs referenced by the Rhythm Game Manager to disk.
  • Load Save File: Load the save file by updating the high scores of matching songs.
  • Delete Save File: Delete the save file.

The Save Manager was designed to only save the high score of the songs. It is recommended to either replace it or built on top of it to allow saving other data specific to your game too.

It is important to know that converting Json to binary is not a secure encryption solution and therefore it is advised to only save data that is relevant to the game and that does not matter if hacked. You may edit or replace the Save Manager to add encryption to your save file.

API

//Get the Save Manager from anywhere using the Toolbox.
m_SaveManager = Toolbox.Get<SaveManager>();

//Return the save folder path.
var saveFolderPath = m_SaveManager.GetSaveFolderPath();

//ResetAllSongHighScores
m_SaveManager.ResetAllSongHighScores();

//Save all song high score to file.
m_SaveManager.SaveAllSongsToFile();

//Load Save File.
m_RhythmProcessor.LoadSaveData();

//Delete From Disk.
m_RhythmProcessor.DeleteFromDisk();

//Save a specific song and then save to disk.
m_RhythmProcessor.SaveSong(song);