SaveObjectAsync
Methods
public StorageOperation SaveObjectAsync(StorageObject storageObject, CancellationToken cancellationToken = default)
Saves a storage object to cloud storage.
Parameters
Type | Name | Description |
---|---|---|
StorageObject | storageObject | The storage object to save. |
CancellationToken | cancellationToken | Used to cancel the operation. |
Returns
Type | Description |
---|---|
StorageOperation | The status of the asynchronous save operation. |
Remarks
If the storage object already exists in cloud storage, all items it previously had will get replaced with the ones in the provided object. Any other items that the storage object had will be removed from it.
Examples
using Coherence.Cloud;
using Coherence.Toolkit;
using UnityEngine;
class CloudStorageSave : MonoBehaviour
{
public CoherenceBridge bridge = null!;
void Start()
{
var cloudStorage = bridge.CloudService.GameServices.CloudStorage;
var objectId = ("type", "id");
var items = new StorageItem[] { ("key1", "value"), ("key2", "value") };
cloudStorage.SaveObjectAsync(objectId, items)
.OnFail(Debug.LogWarning)
.OnSuccess(() => Debug.Log("Saved " + objectId));
}
}
Exceptions
Type | Condition |
---|---|
StorageException | If the user is not logged in via AuthClient, the operation will fail with NotLoggedIn. |
public StorageOperation SaveObjectAsync(StorageObjectId objectId, params StorageItem[] items)
Saves a storage object to cloud storage.
Parameters
Type | Name | Description |
---|---|---|
StorageObjectId | objectId | Identifier of the storage object to save. |
StorageItem[] | items | Specifies all the items that the object should contain in cloud storage after the operation has completed successfully; any other pre-existing items that the object had in cloud storage that are not included in the list will be removed. |
Returns
Type | Description |
---|---|
StorageOperation | The status of the asynchronous save operation. |
Remarks
If the storage object already exists in cloud storage, all items it previously had will get replaced with the ones provided. Any other items that the storage object had will be removed from it.
Examples
using Coherence.Cloud;
using Coherence.Toolkit;
using UnityEngine;
class CloudStorageSave : MonoBehaviour
{
public CoherenceBridge bridge = null!;
void Start()
{
var cloudStorage = bridge.CloudService.GameServices.CloudStorage;
var objectId = ("type", "id");
var items = new StorageItem[] { ("key1", "value"), ("key2", "value") };
cloudStorage.SaveObjectAsync(objectId, items)
.OnFail(Debug.LogWarning)
.OnSuccess(() => Debug.Log("Saved " + objectId));
}
}
Exceptions
Type | Condition |
---|---|
StorageException | If the user is not logged in via AuthClient, the operation will fail with NotLoggedIn. |
public StorageOperation SaveObjectAsync(StorageObjectId objectId, IEnumerable<StorageItem> items, CancellationToken cancellationToken = default)
Saves a storage object to cloud storage.
Parameters
Type | Name | Description |
---|---|---|
StorageObjectId | objectId | Identifier of the storage object to modify. |
IEnumerable<StorageItem> | items | Specifies all the items that the object should contain in cloud storage after the operation has completed successfully; any other pre-existing items that the object had in cloud storage that are not included in the list will be removed. |
CancellationToken | cancellationToken | Used to cancel the operation. |
Returns
Type | Description |
---|---|
StorageOperation | The status of the asynchronous save operation. |
Remarks
If the storage object already exists in cloud storage, all items it previously had will get replaced with the ones provided. Any other items that the storage object had will be removed from it.
Examples
using Coherence.Cloud;
using Coherence.Toolkit;
using UnityEngine;
class CloudStorageSave : MonoBehaviour
{
public CoherenceBridge bridge = null!;
void Start()
{
var cloudStorage = bridge.CloudService.GameServices.CloudStorage;
var objectId = ("type", "id");
var items = new StorageItem[] { ("key1", "value"), ("key2", "value") };
cloudStorage.SaveObjectAsync(objectId, items)
.OnFail(Debug.LogWarning)
.OnSuccess(() => Debug.Log("Saved " + objectId));
}
}
Exceptions
Type | Condition |
---|---|
StorageException | If the user is not logged in via AuthClient, the operation will fail with NotLoggedIn. |