Пример #1
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);
								
							}
						);
					
					}
				
				}
				
			);
			
		}
        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);
            }
        }
Пример #3
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);
    }
Пример #4
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);

	}
Пример #5
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);
    }