Storage

Introduction

A system that provides developers with a flexible storage solution, allowing user data to be stored either locally on the device or securely in the cloud/remote.

What does the system do?

  • Exposes a unified key–value API via LionStorage to store user data (can be primitives or complex objects).

  • Provide multiple Storage types solution based on dev preference,

    • PlayerPrefs

    • Encrypted PlayerPrefs

    • Remote Storage

Usage

  1. Open LionStudios → Settings Manager → Game Interfaces → Storage.

  2. Choose the storage implementation you want (PlayerPrefs, Encrypted PlayerPrefs, or Firestore).

  3. Use the LionStorage API in your code — it’s the same regardless of backend.

Implementation (LionStorage API)

Below is the core API surface with short examples. These calls work the same on all types,

// Available Signatures
public static bool IsDataReady;

// Primitive setter 
public static void SetInt(string key, int value)
public static void SetFloat(string key, float value)
public static void SetString(string key, string value)

// Primivite Getter
public static int GetInt(string key, int defaultVal = 0)
public static float GetFloat(string key, float defaultVal = 0f)
public static string GetString(string key, string defaultVal = "")

// Data check
public static bool HasKey(string key)

// Save
// Note: MergeConflictData is used for remote storage only
public static async Task Save(MergeConflictData mergeConflictData)

// Delete
public static async Task DeleteAll()
public static void DeleteKey(string key)

// Complex Set & Get
public static void SetValue<T>(string key, T value, JsonSerializerSettings jsonSerializerSettings = null)
public static void GetValue<T>(string key, T defaultVal, JsonSerializerSettings jsonSerializerSettings = null)

Primitive setters Example

LionStorage.SetInt("coins", 123);
LionStorage.SetFloat("volume", 0.8f);
LionStorage.SetString("lastLevel", "3-2");

Primitive getters & key checks Example

int coins = LionStorage.GetInt("coins", 0);
float volume = LionStorage.GetFloat("volume", 1f);
string lastLevel = LionStorage.GetString("lastLevel", "1-1");

bool hasCoins = LionStorage.HasKey("coins");

Save Example

// For local or encrypted local
LionStorage.Save(null);

// For remote only
MergeConflictData data = new MergeConflictData();
data.PlayerXP += amount;
await LionStorage.Save(data);

Deleting Example

LionStorage.DeleteKey("lastLevel");
LionStorage.DeleteAll(); // Deletes the current user’s data for the active storage type

Complex-Objects Example

Use the generic helpers to serialize/deserialize complex data (e.g., player profile, inventory). You may pass optional JsonSerializerSettings if you need custom converters or naming.

[Serializable]
public class PlayerProfile {
public string displayName;
public int level;
public List<string> unlockedSkins = new List<string>();
}


var profile = new PlayerProfile {
displayName = "LionStudios",
level = 12,
unlockedSkins = new List<string> { "lion_wing", "tiger_wing" }
};


LionStorage.SetValue<PlayerProfile>("profile", profile, jsonSettings);


PlayerProfile loaded = LionStorage.GetValue<PlayerProfile>(
"profile",
new PlayerProfile(),
jsonSettings
);

Additional Public objects

  • IsDataReady - This boolean will indicate whether or not data is ready to use or not.

if (LionStorage.IsDataReady)
{
    // Add your logic here
}

\

Last updated