Skip to content

Storage

Fridh edited this page May 12, 2024 · 8 revisions

Storage

Storage.cs

The storage script is held by an empty ganeObject called StorageHolder. The gameObject itself is automatically generated when calling Storage.GetStorage() and uses the singleton pattern to persist in between scenes. By using a local JSON the data can easily be stored in between sessions and change in structure upon update of game content.

Adding More Methods

Note that there are to-do lists inside the script file. Read these before you start adding additional methods (search for "TOTO").

If you want to add more methods to the file, make sure to adjust the nested Data class to fit the new desired JSON file structure correctly. The code will change the sotrage.json file's structure to fit this upon the next save. Next, add the variable properties needed (the getters and setters used right now will be removed).

Examples

# Setting username
Storage storage = Storage.GetStorage();

# Music volume
storage.SetMusicVolume(0.5f);
storage.GetMusicVolume();

# Adding a highscore
storage.AddToTopFiveHighscore(Storage.GetUsername() + ":" + score.ToString());

Clone this wiki locally