private SavedGameMetadataUpdate(SavedGameMetadataUpdate.Builder builder)
 {
     this.mDescriptionUpdated = builder.mDescriptionUpdated;
     this.mNewDescription     = builder.mNewDescription;
     this.mCoverImageUpdated  = builder.mCoverImageUpdated;
     this.mNewPngCoverImage   = builder.mNewPngCoverImage;
     this.mNewPlayedTime      = builder.mNewPlayedTime;
 }
Example #2
0
		/// <summary>
		/// Creates the new save. Save returned in callback is closed!. Open it before use.
		/// </summary>
		/// <param name="save">Save.</param>
		/// <param name="saveCreatedCallback">Invoked when save has been created.</param>
		private static void CreateNewSave(ISavedGameMetadata save, Action<ISavedGameMetadata> saveCreatedCallback) {
		
			ISavedGameClient savedGameClient = PlayGamesPlatform.Instance.SavedGame;
			
			SavedGameMetadataUpdate.Builder builder = new SavedGameMetadataUpdate.Builder ();
			builder = builder
				.WithUpdatedPlayedTime(save.TotalTimePlayed.Add(new TimeSpan(0, 0, (int) Time.realtimeSinceStartup)))
				.WithUpdatedDescription("Saved at " + DateTime.Now);
			
			SavedGameMetadataUpdate updatedMetadata = builder.Build();
			
			SaveDataBundle newBundle = new SaveDataBundle(new StoredPlayerData());
			
			savedGameClient.CommitUpdate(
				save, 
				updatedMetadata, 
				SaveDataBundle.ToByteArray(newBundle), 
				(SavedGameRequestStatus status,ISavedGameMetadata game) => {
				
					if (status == SavedGameRequestStatus.Success) {
						m_saveBundleMetadata = game;
						if (saveCreatedCallback != null) saveCreatedCallback(game);
					}
					
					Debug.Log("Creating new save finished with status :" + status.ToString());
				
				}
			);
		}
Example #3
0
		/// <summary>
		/// Commits the save to cloud.
		/// </summary>
		/// <param name="file">Actual save file. This will replace static reference to current save file</param>
		/// <param name="fileName">File name. Used only when saving for first time</param>
		/// <param name="callback">Invoked after commit (true = success)</param>
		private static void CommitSaveToCloud(SaveDataBundle file, string fileName, System.Action<bool> callback) {
			
			ISavedGameClient savedGameClient = PlayGamesPlatform.Instance.SavedGame;
			
			savedGameClient.OpenWithAutomaticConflictResolution(
				
				m_saveBundleMetadata.Filename == string.Empty ? fileName : m_saveBundleMetadata.Filename,
				DataSource.ReadCacheOrNetwork,
				ConflictResolutionStrategy.UseLongestPlaytime,
				(SavedGameRequestStatus reqStatus, ISavedGameMetadata openedGame) => {
					
					if(reqStatus == SavedGameRequestStatus.Success) {
						
						// adding real time since startup so we can determine longes playtime and resolve future conflicts easilly
						m_saveBundleMetadata = openedGame; 
						SavedGameMetadataUpdate.Builder builder = new SavedGameMetadataUpdate.Builder ();
						builder = builder
							.WithUpdatedPlayedTime(timePlayed)
							.WithUpdatedDescription("Saved game at " + DateTime.Now);
						
						if (bannerTexture != null) {
							builder = builder.WithUpdatedPngCoverImage(bannerTexture.EncodeToPNG());
						}
						
						//m_saveBundleMetadata.TotalTimePlayed.Add (new TimeSpan (0, 0, (int)Time.realtimeSinceStartup))
						
						SavedGameMetadataUpdate updatedMetadata = builder.Build();
						
						savedGameClient.CommitUpdate(
							m_saveBundleMetadata,
							updatedMetadata,
							SaveDataBundle.ToByteArray(file),
							(SavedGameRequestStatus status, ISavedGameMetadata game) => {
								
								Debug.Log("SGI CommitUpdate callback invoked with status " + status + ", proceeding...");
								
								if (status == SavedGameRequestStatus.Success) {
									m_saveBundleMetadata = game;
									m_currentSaveBundle = file;
								}
								
								if (callback != null) callback.Invoke(status == SavedGameRequestStatus.Success);
								
							}
						);
					
					}
				
				}
				
			);
			
		}
    internal void ShowWriteSavedGame()
    {
        DrawTitle("WRITE SAVED GAME");
        DrawStatus();

        mSavedGameFileContent = GUI.TextArea(CalcGrid(0, 1), mSavedGameFileContent);

        if (mCurrentSavedGame == null || !mCurrentSavedGame.IsOpen)
        {
            mStatus = "No opened saved game selected.";
            mUi = Ui.SavedGame;
            return;
        }

        var update = new SavedGameMetadataUpdate.Builder()
            .WithUpdatedDescription("Saved at " + DateTime.Now.ToString())
            .WithUpdatedPlayedTime(mCurrentSavedGame.TotalTimePlayed.Add(TimeSpan.FromHours(1)))
            .Build();

        if (GUI.Button(CalcGrid(0, 7), "Write"))
        {
            SetStandBy("Writing update");
            PlayGamesPlatform.Instance.SavedGame.CommitUpdate(
                mCurrentSavedGame,
                update,
                System.Text.ASCIIEncoding.Default.GetBytes(mSavedGameFileContent),
                (status, updated) =>
                {
                    mStatus = "Write status was: " + status;
                    mUi = Ui.SavedGame;
                    EndStandBy();
                });
            mCurrentSavedGame = null;
        }
        else if (GUI.Button(CalcGrid(1, 7), "Cancel"))
        {
            mUi = Ui.SavedGame;
        }
    }
        public void SavedGameOpened(SavedGameRequestStatus status, ISavedGameMetadata game)
        {
            if (status == SavedGameRequestStatus.Success)
            {
                if (mSaving)
                {
                    if (mScreenImage == null)
                    {
                        CaptureScreenshot();
                    }
                    byte[] pngData = (mScreenImage != null) ? mScreenImage.EncodeToPNG() : null;
                    Debug.Log("Saving to " + game);
                    byte[] data = mProgress.ToBytes();
                    TimeSpan playedTime = mProgress.TotalPlayingTime;
                    SavedGameMetadataUpdate.Builder builder = new
                    SavedGameMetadataUpdate.Builder()
                        .WithUpdatedPlayedTime(playedTime)
                        .WithUpdatedDescription("Saved Game at " + DateTime.Now);

                    if (pngData != null)
                    {
                        Debug.Log("Save image of len " + pngData.Length);
                        builder = builder.WithUpdatedPngCoverImage(pngData);
                    }
                    else
                    {
                        Debug.Log("No image avail");
                    }
                    SavedGameMetadataUpdate updatedMetadata = builder.Build();
                    ((PlayGamesPlatform)Social.Active).SavedGame.CommitUpdate(game, updatedMetadata, data, SavedGameWritten);
                }
                else
                {
                    mAutoSaveName = game.Filename;
                    ((PlayGamesPlatform)Social.Active).SavedGame.ReadBinaryData(game, SavedGameLoaded);
                }
            }
            else
            {
                Debug.LogWarning("Error opening game: " + status);
            }
        }
Example #6
0
	/// <summary>
	/// Prepare updated metadata and commit update to GPGS
	/// </summary>
	/// <param name="_gameMetaData">Game meta data.</param>
	/// <param name="savedData">Saved data.</param>
	/// <param name="totalPlaytime">Total playtime.</param>
	static void SaveOnGPGS (ISavedGameMetadata _gameMetaData, byte[] savedData, TimeSpan totalPlaytime) {
		ISavedGameClient savedGameClient = PlayGamesPlatform.Instance.SavedGame;

		Texture2D savedImage = getScreenshot();

		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();
		UIManager.Notify("commiting");
		savedGameClient.CommitUpdate(_gameMetaData, updatedMetadata, savedData, OnSavedGameWritten);

	}
    /*
     * Does the cloud save.
     * Converts PlayerData into a byte array. Updates play time and saved file description. Then commits.
     * */
    public void CloudSave(SavedGameRequestStatus status, ISavedGameMetadata game)
    {
        Save();

        byte[] data = ToBytes(this.playerData);
        //Calculate play time and total playtime.
        TimeSpan delta = DateTime.Now.Subtract(loadedTime);
        playingTime += delta;
        this.timePlayed = playingTime;

        ISavedGameClient savedGameClient = PlayGamesPlatform.Instance.SavedGame;
        SavedGameMetadataUpdate.Builder builder = new SavedGameMetadataUpdate.Builder();
        builder = builder.WithUpdatedPlayedTime(this.timePlayed).WithUpdatedDescription("Current Level: " + playerData.currentGameLevel + " Current Player Level: " + playerData.playerLevel);

        SavedGameMetadataUpdate updatedMetadata = builder.Build();
        savedGameClient.CommitUpdate(game, updatedMetadata, data, OnSaveWritten);
    }
Example #8
0
    void SaveGameData(ISavedGameMetadata game, byte[] savedData)
    {
        ISavedGameClient savedGameClient = PlayGamesPlatform.Instance.SavedGame;

        SavedGameMetadataUpdate.Builder builder = new SavedGameMetadataUpdate.Builder();
        builder = builder
            .WithUpdatedPlayedTime(totalPlaytime)
                .WithUpdatedDescription("Saved game at " + DateTime.Now);
        SavedGameMetadataUpdate updatedMetadata = builder.Build();
        savedGameClient.CommitUpdate(game, updatedMetadata, savedData, OnSavedGameWritten);
    }
Example #9
0
    public void SaveGame(ISavedGameMetadata game, byte[] savedData, System.TimeSpan totalPlaytime, Texture2D img, System.Action<SavedGameRequestStatus, ISavedGameMetadata> callback)
    {
        ISavedGameClient savedGameClient = PlayGamesPlatform.Instance.SavedGame;

        SavedGameMetadataUpdate.Builder builder = new SavedGameMetadataUpdate.Builder();
        builder = builder
            .WithUpdatedPlayedTime(totalPlaytime)
                .WithUpdatedDescription("Saved game at " + System.DateTime.Now);

        if (img != null)
        {
            byte[] pngData = img.EncodeToPNG();
            builder = builder.WithUpdatedPngCoverImage(pngData);
        }

        SavedGameMetadataUpdate updatedMetadata = builder.Build();
        savedGameClient.CommitUpdate(game, updatedMetadata, savedData, callback);
    }
Example #10
0
    public 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);

        // my customization
        Texture2D savedImage = GameObject.FindGameObjectWithTag("GameManager").GetComponent<GameManager>().saveGameImage;
        // end my customization

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