PlayerPrefsSaver
Coding Style wiki
PlayerPrefsSaver is the built-in runtime saver of the SaverSystem (inherits Saver). It uses UnityEngine.PlayerPrefs as the storage backend, and every Save* automatically calls PlayerPrefs.Save() to write immediately; the base class text-content data feature (Data Map) is available directly.
| Namespace | OxGKit.SaverSystem |
| Type | public class PlayerPrefsSaver : Saver |
| Source | PlayerPrefsSaver.cs |
using OxGKit.SaverSystem;
Quick Start
using OxGKit.SaverSystem;
// Create a runtime saver (PlayerPrefs backend)
Saver saver = new PlayerPrefsSaver();
// Basic access
saver.SaveString("name", "michael");
saver.SaveInt("language", 2);
saver.SaveFloat("bgmVolume", 0.8f);
// Text-content data feature (provided by the Saver base class)
saver.SaveData("appPrefs", "lastLogin", "2026-07-29");
string lastLogin = saver.GetData("appPrefs", "lastLogin", null);
General Rules
Scope
| Saver | Storage Backend | Scope |
|---|---|---|
PlayerPrefsSaver | UnityEngine.PlayerPrefs | Runtime (in-game settings, stored per application/platform) |
| EditorPrefsSaver | UnityEditor.EditorPrefs | Editor only (editor tool preferences) |
(See the Module Intro for an overview)
Write Timing
Attention Every Save* automatically calls PlayerPrefs.Save() to write to disk immediately; DeleteKey / DeleteAll do not call Save() additionally (by Unity default they are written on normal application quit — call PlayerPrefs.Save() yourself if needed).
Reminder The PlayerPrefs storage location differs per platform (e.g., the registry on Windows, browser IndexedDB on WebGL); on WebGL persistence relies on the browser flushing, and avoid storing huge strings.
Overridden Members
Method Overview
| Method | Description |
|---|---|
| SaveString | Saves a string and writes immediately. |
| GetString | Gets a string. |
| SaveInt | Saves an int and writes immediately. |
| GetInt | Gets an int. |
| SaveFloat | Saves a float and writes immediately. |
| GetFloat | Gets a float. |
| HasKey | Checks whether a key exists. |
| DeleteKey | Deletes a key. |
| DeleteAll | Deletes all PlayerPrefs keys. |
SaveString
public override void SaveString(string key, string value)
Saves a string via PlayerPrefs.SetString, then calls PlayerPrefs.Save() immediately to write.
saver.SaveString("name", "michael");
GetString
public override string GetString(string key, string defaultValue = "")
Gets a string via PlayerPrefs.GetString; returns defaultValue when the key does not exist.
SaveInt
public override void SaveInt(string key, int value)
Saves an int via PlayerPrefs.SetInt, then calls PlayerPrefs.Save() immediately to write.
GetInt
public override int GetInt(string key, int defaultValue = 0)
Gets an int via PlayerPrefs.GetInt; returns defaultValue when the key does not exist.
SaveFloat
public override void SaveFloat(string key, float value)
Saves a float via PlayerPrefs.SetFloat, then calls PlayerPrefs.Save() immediately to write.
GetFloat
public override float GetFloat(string key, float defaultValue = 0f)
Gets a float via PlayerPrefs.GetFloat; returns defaultValue when the key does not exist.
HasKey
public override bool HasKey(string key)
Checks whether the specified key exists via PlayerPrefs.HasKey.
DeleteKey
public override void DeleteKey(string key)
Deletes the specified key via PlayerPrefs.DeleteKey.
DeleteAll
public override void DeleteAll()
Deletes keys via PlayerPrefs.DeleteAll.
Important PlayerPrefs.DeleteAll deletes ALL PlayerPrefs keys of this application (including keys not stored through this saver) — use with caution.