User Data

Store and manage player data to enhance gameplay experience and retain progress.

There are two types of storage: local (LocalStorage) and internal (PlatformInternal). When writing to local storage, data is saved on the player's device. When writing to internal storage, data is saved on the platform's servers.

Default Storage Type

Identify the default storage type to understand where data is being saved (local or server).

Bridge.storage.defaultType

Used automatically if no specific storage type is specified when working with data. Possible values: LocalStorage, PlatformInternal.

Support Check

Verify if the specified storage type is supported on the platform to ensure compatibility.

Bridge.storage.IsSupported(StorageType.LocalStorage)
Bridge.storage.IsSupported(StorageType.PlatformInternal)

Availability Check

Check if the specified storage type is currently available for use to manage data storage effectively.

Bridge.storage.IsAvailable(StorageType.LocalStorage)
Bridge.storage.IsAvailable(StorageType.PlatformInternal)

Load Data

Retrieve stored data based on a key or multiple keys to restore player progress or settings.

// Get data by key
private void Start()
{
    Bridge.storage.Get("level", OnStorageGetCompleted);
}

private void OnStorageGetCompleted(bool success, string data)
{
    // Loading succeeded
    if (success)
    {
        if (data != null)
        {
            Debug.Log(data);
        }
        else
        {
            // No data for the key 'level'
        }
    }
    else
    {
        // Error, something went wrong
    }
}

// Get data by multiple keys
private void Start()
{
    Bridge.storage.Get(new List<string>() { "level", "coins" }, OnStorageGetCompleted);
}

private void OnStorageGetCompleted(bool success, List<string> data)
{
    // Loading succeeded
    if (success)
    {
        if (data[0] != null)
        {
            Debug.Log($"Level: {data[0]}");
        }
        else
        {
            // No data for the key 'level'
        }

        if (data[1] != null)
        {
            Debug.Log($"Coins: {data[1]}");
        }
        else
        {
            // No data for the key 'coins'
        }
    }
    else
    {
        // Error, something went wrong
    }
}

// Get data from a specific storage type
private void Start()
{
    Bridge.storage.Get("level", OnStorageGetCompleted, StorageType.LocalStorage);
}

private void OnStorageGetCompleted(bool success, string data)
{
    // Loading succeeded
    if (success)
    {
        if (data != null)
        {
            Debug.Log(data);
        }
        else
        {
            // No data for the key 'level'
        }
    }
    else
    {
        // Error, something went wrong
    }
}

Save Data

Save data to the specified storage with a key to retain player progress or settings.

// Save data by key
private void Start()
{
    Bridge.storage.Set("level", "dungeon_123", OnStorageSetCompleted);
}

private void OnStorageSetCompleted(bool success)
{
    Debug.Log($"OnStorageSetCompleted, success: {success}");
}

// Save data by multiple keys
private void Start()
{
    var keys = new List<string>() { "level", "is_tutorial_completed", "coins" };
    var data = new List<object>() { "dungeon_123", true, 12 };
    Bridge.storage.Set(keys, data, OnStorageSetCompleted);
}

// Save data to a specific storage type
private void Start()
{
    Bridge.storage.Set("level", "dungeon_123", OnStorageSetCompleted, StorageType.LocalStorage);
}

Delete Data

Remove data from the specified storage by key to manage player data and settings effectively.

// Delete data by key
private void Start()
{
    Bridge.storage.Delete("level", OnStorageDeleteCompleted);
}

private void OnStorageDeleteCompleted(bool success)
{
    Debug.Log($"OnStorageDeleteCompleted, success: {success}");
}

// Delete data by multiple keys
private void Start()
{
    var keys = new List<string>() { "level", "is_tutorial_completed", "coins" };
    Bridge.storage.Delete(keys, OnStorageDeleteCompleted);
}

// Delete data from a specific storage type
private void Start()
{
    Bridge.storage.Delete("level", OnStorageDeleteCompleted, StorageType.LocalStorage);
}

If no specific storage type is passed as the third argument when working with data, the default storage type Bridge.storage.defaultType is used.

Last updated