Cloud Saving and Loading
First, you need to add using BayatGames.SaveGamePro.Networking;
at top of your script to use Save Game Pro Cloud API.
The Save Game Pro Cloud API uses Coroutines to handle the Asynchronous code, but some of the APIs such as PlayFab and Firebase provide callbacks to handle this.
You can use Callbacks or Coroutines as your need, but the Coroutines are recommended because of the Unity nature.
Here is a simple usage example of Save Game Pro Cloud – Web API, the Web API uses Coroutines:
SaveGameWeb web = new SaveGameWeb ( "http://example.com", "MySecretKey", "username", "password" );
yield return StartCoroutine ( web.Save ( "score", 12 ) );
if ( web.Request.isHttpError || web.Request.isNetworkError ) {
Debug.LogError ( "Save Failed" );
Debug.LogError ( "Request Error: " + web.Request.error );
Debug.LogError ( "Cloud Error: " + web.Request.downloadHandler.text );
} else {
Debug.Log ( "Save Successful" );
Debug.Log ( "Cloud Response: " + web.Request.downloadHandler.text );
}
And loading the data from Cloud:
SaveGameWeb web = new SaveGameWeb ( "http://example.com", "MySecretKey", "username", "password" );
yield return StartCoroutine ( web.Download ( "score" ) );
if ( web.Request.isHttpError || web.Request.isNetworkError ) {
Debug.LogError ( "Load Failed" );
Debug.LogError ( "Request Error: " + web.Request.error );
Debug.LogError ( "Cloud Error: " + web.Request.downloadHandler.text );
} else {
Debug.Log ( "Load Successful" );
int score = web.Load<int> ();
Debug.Log ( "Score: " + score.ToString () );
}
For connecting to the server you need to provide a secret key to authorize yourself and connect to the server, this secret key could be provided by Save Game Pro server-side integration or created by yourself.
By using this API you can save & load data from most popular database engines such as MySQL and MongoDB in different programming languages such as PHP and Node.js, here is a list of Save Game Pro server-side integrations:
More database engines and programming languages will be available in future updates.
You can use these integrations to handle the request or you can make an integration from scratch and handle the data yourself.
Also, Save Game Pro includes integrations for most popular backend services such as Firebase and PlayFab to make it easy for you to save your game data: