Helper class that uses cookies in WebGL builds and PlayerPrefs on other platforms.
Although Unity WebGL applications support PlayerPrefs
, the storage is tightly bound to a specific build.
This means that the data stored there becomes inaccessible once you update your application.
That is why you should use cookies instead of PlayerPrefs
to store persistent data.
Unity WebGL Cookies package needed
Use Unity Package Manager to add the package using the URL of this repository.
using MiniIT.Storage;
public class SharedPrefsExample
{
public void DoSomething()
{
// Static methods
string value = SharedPrefs.GetString("some.string.key", "Optional default value");
SharedPrefs.SetInt("PlayerHealth", 100);
// Local reference
ISharedPrefs prefs = SharedPrefs.Instance;
prefs.SetBool("SoundEnabled", true);
float volume = prefs.GetFloat("MusicVolume", 1f);
}
}