ToBytes() public method

public ToBytes ( ) : byte[]
return byte[]
Exemplo n.º 1
0
 void SaveToCloud()
 {
     if (Authenticated)
     {
         // Cloud save is not in ISocialPlatform, it's a Play Games extension,
         // so we have to break the abstraction and use PlayGamesPlatform:
         Debug.Log("Saving progress to the cloud...");
         ((PlayGamesPlatform)Social.Active).UpdateState(0, mProgress.ToBytes(), this);
     }
 }
    public void SavedGameOpened(SavedGameRequestStatus status, ISavedGameMetadata game)
    {
        if (status == SavedGameRequestStatus.Success)
        {
            if (mSaving)
            {
                if (mScreenImage == null)
                {
                    CaptureScreenshot();
                }

                byte[] pngData = null;
                if (mScreenImage != null)
                {
                    pngData = mScreenImage.EncodeToPNG();
                }

                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
            {
                ((PlayGamesPlatform)Social.Active).SavedGame.ReadBinaryData(
                    game, SavedGameLoaded);
            }
        }
        else
        {
            Debug.LogWarning("Error opening game: " + status);
        }
    }
Exemplo n.º 3
0
    public byte[] OnStateConflict(int slot, byte[] local, byte[] server)
    {
        Debug.Log("Conflict callback called. Resolving conflict.");

        // decode byte arrays into game progress and merge them
        GameProgress localProgress = local == null ?
                                     new GameProgress() : GameProgress.FromBytes(local);
        GameProgress serverProgress = server == null ?
                                      new GameProgress() : GameProgress.FromBytes(server);

        localProgress.MergeWith(serverProgress);

        // resolve conflict
        return(localProgress.ToBytes());
    }