Hi all! I-m trying yo implement the Google Play Services in my Android game.
I have been able to implement achievments without problems and are working good, but I have been some days trying to get the Saved Services working and I can´t.
The main problem is the code of the plugin page, I don´t understand how it works, only I have been able to showUI with a button but I dont pass from that point.
I need the new Saved Service, not the old one Cloud Services, thats the main problem, for the old Cloud Service are a lot of tutorial, but for the new one I can´t fine anything.
I have enable Saved Games in Google Developers Console and it is publishied more than 24 hours ago (2 days exactly).
I have enabled Saved Games in the code:
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
// enables saving game progress.
.EnableSavedGames()
.Build();
PlayGamesPlatform.InitializeInstance(config);
This is the code provided with the plugin:
To show the default UI:
void ShowSelectUI() {
int maxNumToDisplay = 5;
bool allowCreateNew = false;
bool allowDelete = true;
ISavedGameClient savedGameClient = PlayGamesPlatform.Instance.SavedGame;
savedGameClient.ShowSelectSavedGameUI("Select saved game",
maxNumToDisplay,
allowCreateNew,
allowDelete,
OnSavedGameSelected);
}
public void OnSavedGameSelected (SelectUIStatus status, ISavedGameMetadata game) {
if (status == SelectUIStatus.SavedGameSelected) {
// handle selected game save
} else {
// handle cancel or error
}
}
To open save game:
void OpenSavedGame(string filename) {
ISavedGameClient savedGameClient = PlayGamesPlatform.Instance.SavedGame;
savedGameClient.OpenWithAutomaticConflictResolution(filename, DataSource.ReadCacheOrNetwork,
ConflictResolutionStrategy.UseLongestPlaytime, OnSavedGameOpened);
}
public void OnSavedGameOpened(SavedGameRequestStatus status, ISavedGameMetadata game) {
if (status == SavedGameRequestStatus.Success) {
// handle reading or writing of saved game.
} else {
// handle error
}
}
Writing save game:
void SaveGame (ISavedGameMetadata game, byte[] savedData, TimeSpan totalPlaytime) {
ISavedGameClient savedGameClient = PlayGamesPlatform.Instance.SavedGame;
SavedGameMetadataUpdate.Builder builder = new SavedGameMetadataUpdate.Builder();
builder = builder
.WithUpdatedPlayedTime(totalPlaytime)
.WithUpdatedDescription("Saved game at " + DateTime.Now());
if (savedImage != null) {
// This assumes that savedImage is an instance of Texture2D
// and that you have already called a function equivalent to
// getScreenshot() to set savedImage
// NOTE: see sample definition of getScreenshot() method below
byte[] pngData = savedImage.EncodeToPNG();
builder = builder.WithUpdatedPngCoverImage(pngData);
}
SavedGameMetadataUpdate updatedMetadata = builder.Build();
savedGameClient.CommitUpdate(game, updatedMetadata, savedData, OnSavedGameWritten);
}
public void OnSavedGameWritten (SavedGameRequestStatus status, ISavedGameMetadata game) {
if (status == SavedGameRequestStatus.Success) {
// handle reading or writing of saved game.
} else {
// handle error
}
}
public Texture2D getScreenshot() {
// Create a 2D texture that is 1024x700 pixels from which the PNG will be
// extracted
Texture2D screenShot = new Texture2D(1024, 700);
// Takes the screenshot from top left hand corner of screen and maps to top
// left hand corner of screenShot texture
screenShot.ReadPixels(
new Rect(0, 0, Screen.width, (Screen.width/1024)*700), 0, 0);
return screenShot;
}
Reading save game:
void LoadGameData (ISavedGameMetadata game) {
ISavedGameClient savedGameClient = PlayGamesPlatform.Instance.SavedGame;
savedGameClient.ReadBinaryData(game, OnSavedGameDataRead);
}
public void OnSavedGameDataRead (SavedGameRequestStatus status, byte[] data) {
if (status == SavedGameRequestStatus.Success) {
// handle processing the byte array data
} else {
// handle error
}
}
Thanks for your time!