Cloud Storage

The cloud storage provides a persistence layer for the project.

CloudService.GameServices.CloudStorage

This class provides methods to save, load and delete storage objects in the cloud.

Example

using Coherence.Cloud;
using Coherence.Toolkit;
using System.Threading.Tasks;
using UnityEngine;

public class CloudStorageExample : MonoBehaviour
{
    public CoherenceBridge bridge;
    public StorageObjectId storageObjectId;

    async void Start()
    {
        var cloudStorage = bridge.CloudService.GameServices.CloudStorage;
        await SaveItemsAsync(cloudStorage, storageObjectId);
        await LoadItemsAsync(cloudStorage, storageObjectId);
    }

    private async Task SaveItemsAsync(CloudStorage cloudStorage, StorageObjectId objectId)
    {
        var itemsToSave = new StorageObjectMutation.Full(objectId)
        {
            ["Key 1"] = 1,
            ["Key 2"] = 2,
            ["Key 3"] = 3,
        };

        await cloudStorage.SaveAsync(itemsToSave);

        Debug.Log("Items saved.");
    }

    private async Task LoadItemsAsync(CloudStorage cloudStorage, StorageObjectId objectId)
    {
        var loadedItems = await cloudStorage.LoadAsync(objectId);

        foreach (var item in loadedItems)
        {
            Debug.Log($"Item loaded: '{item.Key}': {item.Value}");
        }
    }
}

Limitations

Requests: SaveAsync/LoadAsync/DeleteAsync can be called unlimited amount of times but the execution may be throttled.

Last updated

Was this helpful?