Xbox Cloud Saving
First, make sure you have installed Save Game Pro Xbox Cloud integration successfully.
Save Game Pro uses Xbox Connected Storage to save and load data in Xbox (when the integration is installed, otherwise it will use PlayerPrefs on this platform which uses simple key-value pair storage that is too limited for persisting game data).
First, you need to sign in the user, to do so you can use the Xbox Gamepad ID as user ID, here is a sample on how to do so: (For more information check out this guide: Unity Prefabs and Scripted Sign-in)
gamepadIndex = XboxOneInput.GetGamepadIndexFromGamepadButton(XboxOneKeyCode.Gamepad1ButtonA);
int userId = XboxOneInput.GetUserIdForGamepad(gamepadIndex);
Now you need to first create a Storage and a Container:
this.cloud = new SaveGameXboxCloud();
CreateConnectedStorageOp op = this.cloud.CreateStorage(userint, "myContainer");
while (!op.IsComplete)
{
yield return null;
}
Here is a simple usage example of Connected storage save:
SubmitDataMapUpdatesAsyncOp op = this.cloud.Save("myData", "My Custom Data");
while (!op.IsComplete)
{
yield return null;
}
// Save is completed, you can do other actions here
// Also, this operation should be done inside a Coroutine using IEnumerator
As you can see, these operations are Async, so you need to use Coroutines (IEnumerator) to complete these operations.
Now here is how to do a simple load:
GetDataMapViewAsyncOp op = this.cloud.Download("myData");
while (!op.IsComplete)
{
yield return null;
}
string data = cloud.Load<string>(); // Output: "My Custom Data"
Deleting data:
SubmitDataMapUpdatesAsyncOp op = this.cloud.Delete("myData");
while (!op.IsComplete)
{
yield return null;
}
Delete container:
DeleteContainerAsyncOp op = this.cloud.DeleteContainer("myContainer");
while (!op.IsComplete)
{
yield return null;
}
For more information, check out the working example included in the Examples folder of Save Game Pro named Xbox Cloud Storage. (This example has been made by a partner, not by Bayat Games)