Skip to content

Mini-IT/unity-sharedprefs

Repository files navigation

Unity Shared Preferences

Helper class that uses cookies in WebGL builds and PlayerPrefs on other platforms.

Motivation

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.

Dependencies

Unity WebGL Cookies package needed

Installation

Use Unity Package Manager to add the package using the URL of this repository.

Usage

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);
  }
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages