Пример #1
0
    // Load the game
    public void LoadGame()
    {
//		print ("load");
        // Check if signed in
        if (PlayGamesPlatform.Instance.localUser.authenticated)
        {
//			print ("auth");
            // Read binary callback
            Action <SavedGameRequestStatus, byte[]> readBinaryCallback =
                (SavedGameRequestStatus status, byte[] data) => {
//					print (status + " " + SavedGameRequestStatus.Success);

                // Check if read was successful
                if (status == SavedGameRequestStatus.Success)
                {
                    // Load game data
//						try {
//							print ("7");

                    //SaveData saveData = SaveData.FromBytes (data);

                    SaveDataManager.instance.cloudPlayerSavedData = SaveDataManager.FromBytes(data);
                    SaveDataManager.instance.ResolveDataConflict();
                    SaveDataManager.instance.ToJSON();
//							print (SaveDataManager.instance.json);
//						t1.text = SaveDataManager.instance.json;
//							t3.text = SaveDataManager.instance.json;

                    //	SaveDataManager.instance.OverridePlayerPrefs();

                    //
                    //						// We are displaying these values for the purpose of the tutorial.
                    //						// Normally you would set the values here.
                    //						Debug.Log ("Player name = " + saveData.playerName);
                    //						Debug.Log ("Player health = " + saveData.playerHealth);
                    //						Debug.Log ("Player score = " + saveData.playerScore);
                    //Debug.Log(saveData);
//						} catch (Exception e) {
//
//							print ("77"+e.Message);
////							Debug.LogError ("Failed to read binary data: " + e.ToString ());
////							t1.text = "Failed to read binary data: " + e.ToString ();
//						}
                }
                else
                {
//						print (status);
//						print (status + " " + SavedGameRequestStatus.Success);
                }
            };

            // Read game callback
            Action <SavedGameRequestStatus, ISavedGameMetadata> readCallback =
                (SavedGameRequestStatus status, ISavedGameMetadata game) => {
                // Check if read was successful
                if (status == SavedGameRequestStatus.Success)
                {
                    currentGame = game;
                    PlayGamesPlatform.Instance.SavedGame.ReadBinaryData(game, readBinaryCallback);
                }
            };

//			// Replace "MySaveGame" with whatever you would like to save file to be called
//			ReadSaveGame ("MySaveGameTest1", readCallback);


//			// for T E S T
//			try{ReadSaveGame ("MySaveGameTest3", readCallback);

            // for R E A L   S A V E
//			try {
//				ReadSaveGame ("SaveGameProgress", readCallback);
//			} catch (Exception e) {
////				t2.text = e.Message;
//				print (e.Message);
//			}


            ReadSaveGame("SaveGameProgress", readCallback);
        }
        else
        {
//			print ("blom auth");
        }
    }