Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving to Google Play Cloud Save Automatically

BACKGROUND
I'm working on an android game that has been published on Google Play Store.
And now I'm planning to add Cloud Save feature as an update.
(FYI: I'm using Unity and Play Games plugin)

PROBLEM
After hours of research and experiment, I'm currently stuck on how to save the game automatically.

My game is a collection of mini games where a player can keep playing until he runs out of lives.
I want the save to happen automatically at the time the player loses.

According to the plugin, this is how I save to the cloud:

public void SaveGame (ISavedGameMetadata game, byte[] savedData) {
    /* code omitted */
    savedGameClient.CommitUpdate(game, updatedMetadata, savedData, OnSavedGameWritten);
}

I need 2 parameters for the function SaveGame, the 1st one is the meta data, then the 2nd one is the data itself.

Everywhere I search (even in Google), I cannot find a way to generate the meta data automatically.
Based on my research, I can get the meta data from the function below:

void ShowSelectUI() {
    uint maxNumToDisplay = 5;
    bool allowCreateNew = true;
    bool allowDelete = true;

    // I will need to call this function first
    // This will display a dialog to the player
    // The player will need to create a new save manually afterwards
    ISavedGameClient savedGameClient = PlayGamesPlatform.Instance.SavedGame;
    savedGameClient.ShowSelectSavedGameUI("Select saved game",
                                          maxNumToDisplay,
                                          allowCreateNew,
                                          allowDelete,
                                          OnSavedGameSelected);
}


public void OnSavedGameSelected (SelectUIStatus status, ISavedGameMetadata game) {
    // And then from the callback function I get the meta data
    // (ISavedGameMetadata game)

    if (status == SelectUIStatus.SavedGameSelected) {
        // handle selected game save
    } else {
        // handle cancel or error
    }
}

This way user will need to open up a dialog and then create a new save by himself.
That can't happen in my game, as I need to save every time the player loses.

REFERENCE
I know that it should be possible, a game called Get Bigger! Mola could save the progress each time the player loses without opening up a save dialog.

QUESTION
Can anyone give me any clues about this?
I have spent my entire day searching without an answer...
Any kind of help will be greatly appreciated.

like image 541
Jay Kazama Avatar asked Jun 07 '15 15:06

Jay Kazama


1 Answers

As mentioned here, you can open a new snapshot without having to select one from a list, just specify the filename, if it exist, it will use it, otherwise it will create a new one.

Something like this:

        ISavedGameClient savedGameClient = PlayGamesPlatform.Instance.SavedGame;
    savedGameClient.OpenWithAutomaticConflictResolution(filename, DataSource.ReadCacheOrNetwork,
        ConflictResolutionStrategy.UseLongestPlaytime, delegate(SavedGameRequestStatus status, ISavedGameMetadata metadata) {
            // your code here ....
        });
like image 56
arielsan Avatar answered Oct 13 '22 09:10

arielsan