以编程方式从 google play 游戏中删除保存的游戏
Posted
技术标签:
【中文标题】以编程方式从 google play 游戏中删除保存的游戏【英文标题】:Delete saved game from google play games programmatically 【发布时间】:2016-08-09 21:33:40 【问题描述】:我们想使用 google play 游戏在 Unity 中备份/恢复我们的 android 游戏。 为此,我们使用play-games-plugin-for-unity 。 使用 github 中引入的 ShowSelectUI() 方法,用户可以手动删除保存的游戏。 现在的问题是我们想在 UI 中提供一个按钮,通过单击用户可以删除保存的游戏,有没有办法以编程方式进行删除操作? 提前致谢。
【问题讨论】:
【参考方案1】:如果您知道要删除的已保存游戏实例的名称,则可以调用 Open,然后在获得 savedData 的元数据后,调用 Delete:
void DeleteSavedGame(string filename)
ISavedGameClient savedGameClient = PlayGamesPlatform.Instance.SavedGame;
savedGameClient.OpenWithAutomaticConflictResolution(filename, DataSource.ReadCacheOrNetwork,
ConflictResolutionStrategy.UseLongestPlaytime, OnDeleteSavedGame);
public void OnDeleteSavedGame(SavedGameRequestStatus status, ISavedGameMetadata game)
ISavedGameClient savedGameClient = PlayGamesPlatform.Instance.SavedGame;
if (status == SavedGameRequestStatus.Success)
// delete the game.
savedGameClient.Delete(game);
else
// handle error
【讨论】:
【参考方案2】:我最终按照上面的@claytonWilkinson 实现了这个。然后我添加了 DeleteGoogleCloudSave() 来点击一个按钮:
public void DeleteGoogleCloudSave()
#if UNITY_ANDROID && !UNITY_EDITOR
Debug.Log("Opening save...");
if (isGooglePlayGamesConnected())
((PlayGamesPlatform)Social.Active).SavedGame.OpenWithAutomaticConflictResolution("Filename", GooglePlayGames.BasicApi.DataSource.ReadCacheOrNetwork,ConflictResolutionStrategy.UseLongestPlaytime, DeleteSavedGameOpened);
#endif
void DeleteSavedGameOpened(SavedGameRequestStatus status, ISavedGameMetadata meta)
#if UNITY_ANDROID && !UNITY_EDITOR
Debug.Log("Running SaveGameOpened...");
if(status == SavedGameRequestStatus.Success)
DeleteSavedGame();
#endif
void DeleteSavedGame()
ISavedGameClient savedGameClient = PlayGamesPlatform.Instance.SavedGame;
savedGameClient.OpenWithAutomaticConflictResolution("Filename", DataSource.ReadCacheOrNetwork,ConflictResolutionStrategy.UseLongestPlaytime, OnDeleteSavedGame);
public void OnDeleteSavedGame(SavedGameRequestStatus status, ISavedGameMetadata game)
ISavedGameClient savedGameClient = PlayGamesPlatform.Instance.SavedGame;
if (status == SavedGameRequestStatus.Success)
// delete the game.
savedGameClient.Delete(game);
Debug.Log("Google Cloud Save Game has been deleted...");
else
// handle error
Debug.LogError("Google Cloud Save Game has NOT been deleted...");
【讨论】:
以上是关于以编程方式从 google play 游戏中删除保存的游戏的主要内容,如果未能解决你的问题,请参考以下文章
如何从 Google Play 应用或游戏列表页面中删除屏幕截图
如何从 Google Play 游戏服务排行榜中删除被黑分数?
Google play 游戏服务 - 从应用程序以横向模式启动 google+ 登录流程