CloudStorage
CloudStorage is a service that allows you to save and load objects (StorageObject) to and from the backend.
Examples
using Coherence.Toolkit;
using UnityEngine;
class CloudStorageExample : MonoBehaviour
{
public CoherenceBridge bridge = null!;
void Start()
{
var cloudStorage = bridge.CloudService.GameServices.CloudStorage;
var objectId = ("type", "id");
var item = ("key", "value");
cloudStorage.SaveObjectAsync(objectId, item)
.OnFail(Debug.LogWarning)
.OnSuccess(() => Debug.Log("Saved"));
}
}
Remarks
You must be logged in to coherence Cloud to use the service. IsReady will be false when you are not logged in. If you try using the service while IsReady is false, the operation will fail with NotLoggedIn.
Note that the service has a rate limit of one request of a particular type per second. What this means is that if, for example, a save operation is made while another save operation is already in progress, then the second save operation will be queued, and will only get sent to the backend after one second has passed since the previous save operation.
However, the service can in most cases automatically batch multiple requests into a single one, which means that in practice an operation should not have to sit in queue for more than one second, except in rare circumstances where the same objects are being targeted by a combination of both SaveObjectAsync and DeleteObjectAsync operations, which can not be batched together into a single operation.
Each operation returns a storage operation object.
An async method can await the result object to wait until the operation has completed.
Similarly, a Coroutine can yield the result object to wait for it to complete.
Properties
IsBusy | Gets a value indicating whether there are currently any save, delete or load operations in progress. |
IsReady | Gets a value indicating if the service is ready to be used. |
Methods
DeleteObjectAsync | Deletes a storage object from cloud storage. |
LoadObjectAsync | Loads a storage object from cloud storage. |
SaveObjectAsync | Saves a storage object to cloud storage. |