Jay Kazama
Jay Kazama

Reputation: 3277

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.

Upvotes: 7

Views: 3737

Answers (2)

arielsan
arielsan

Reputation: 428

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 ....
        });

Upvotes: 2

Ori Frish
Ori Frish

Reputation: 411

I personally am not familiar with the asset you try to save the stats with. However, I did use this asset Stan's Native which I personally can recommend.

If you want something else for free, there's these links, Search Native

anyway, you should check Google Tutorials about working with theie cloud, there's a lot of information, on the Android site, that doesn't involve Unity. Android Developer

Upvotes: 0

Related Questions