Saved Games

Implement saved games using the cross-platform Ultimate Mobile API based on Google Play Snapshots & iOS Game Saves API.

 

Before you begin you might want to check out the configuration guides for platforms you want to have:

Saved Games List

Use the FetchSavedGames method to retrieve available saved games list and display inside your application UI, allowing a player to pick a game save he needs. See the code snippet below:

using SA.CrossPlatform.GameServices;
...

var client = UM_GameService.SavedGamesClient;
client.FetchSavedGames((result) => {
    if(result.IsSucceeded) {
        foreach(var snapshot in result.Snapshots) {
            Debug.Log("snapshot.Name: " + snapshot.Name);
            Debug.Log("snapshot.DeviceName: " + snapshot.DeviceName);
        }
    } else {
        Debug.LogError("FetchSavedGames failed: " + result.Error.FullMessage);
    }
});

Load Game Data

Once a user picked game save he wanted to load from the available saves list, you may download save binary data using the LoadGameData method.

using SA.CrossPlatform.GameServices;
...

public void LoadGame(UM_iSavedGameMetadata game) {
    var client = UM_GameService.SavedGamesClient;
    client.LoadGameData(game, (result) => {
        if (result.IsSucceeded) {
            UM_SavedGameData data = result.SavedGame;
            Debug.Log("Data size (bytes): " + data.Data.Length);
            //Restore your game progress here
        } else {
            Debug.LogError("Failed to load saved game data: " + result.Error.FullMessage);
        }
    });
}

Saving a Game

You may also create a new game save using the SaveGame method.

using SA.CrossPlatform.GameServices;
...

public void SaveGame(byte[] gameData) {
    var client = UM_GameService.SavedGamesClient;
    UM_SavedGameData data = new UM_SavedGameData(gameData);
    client.SaveGame("MySave", data, (result) => {
        if(result.IsSucceeded) {
            Debug.Log("Game saved");
        } else {
            Debug.Log("Failed to save: " + result.Error.FullMessage);
        }
    });
}

Delete Game Save

If you wish to provide an ability to delete user-created game saves, please use the Delete method.

using SA.CrossPlatform.GameServices;
...

public void DeleteGameSave(UM_iSavedGameMetadata game) {
    var client = UM_GameService.SavedGamesClient;
    client.Delete(game, (result) => {
        if (result.IsSucceeded) {
            Debug.Log("Game Deleted");
        } else {
            Debug.Log("Failed to delete: " + result.Error.FullMessage);
        }
    });
}