【问题标题】:Delete saved game from google play games programmatically以编程方式从 google play 游戏中删除保存的游戏
【发布时间】:2016-08-09 21:33:40
【问题描述】:

我们想使用 google play 游戏在 Unity 中备份/恢复我们的 android 游戏。 为此,我们使用play-games-plugin-for-unity 。 使用 github 中引入的 ShowSelectUI() 方法,用户可以手动删除保存的游戏。 现在的问题是我们想在 UI 中提供一个按钮,通过单击用户可以删除保存的游戏,有没有办法以编程方式进行删除操作? 提前致谢。

【问题讨论】:

    标签: unity3d google-play-games


    【解决方案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...");
          }
      }
      

      【讨论】:

        猜你喜欢
        • 2019-04-25
        • 2020-06-17
        • 2022-08-05
        • 1970-01-01
        • 2019-11-19
        • 1970-01-01
        • 2016-06-27
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多