CloudService.GameServices.CloudStorage
This class provides methods to save, load and delete storage objects in the cloud.
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}");
}
}
}