Пример #1
0
        private void UpdateUserStatsCallback(UpdateUserStatisticsResult result)
        {
            var testContext = (UUnitTestContext)result.CustomData;

            var getRequest = new GetUserStatisticsRequest();
            PlayFabClientAPI.GetUserStatistics(getRequest, PlayFabUUnitUtils.ApiCallbackWrapper<GetUserStatisticsResult>(testContext, GetUserStatsCallback2), SharedErrorCallback, testContext);
        }
	// Example for getting the user statistics for a player.
	IEnumerator GetUserStats(float sec = 0)
	{
		yield return new WaitForSeconds(sec);
		GetUserStatisticsRequest request = new GetUserStatisticsRequest();
		PlayFabClientAPI.GetUserStatistics(request, OnGetUserStatsSuccess, OnPlayFabError);
	}
Пример #3
0
		/// <summary>
		/// Retrieves the details of all title-specific statistics for the user
		/// </summary>
		public static void GetUserStatistics(GetUserStatisticsRequest request, GetUserStatisticsCallback resultCallback, ErrorCallback errorCallback)
		{
			if (AuthKey == null) throw new Exception ("Must be logged in to call this method");

			string serializedJSON = JsonConvert.SerializeObject(request, Util.JsonFormatting, Util.JsonSettings);
			Action<string,string> callback = delegate(string responseStr, string errorStr)
			{
				GetUserStatisticsResult result = null;
				PlayFabError error = null;
				ResultContainer<GetUserStatisticsResult>.HandleResults(responseStr, errorStr, out result, out error);
				if(error != null && errorCallback != null)
				{
					errorCallback(error);
				}
				if(result != null)
				{
					
					if(resultCallback != null)
					{
						resultCallback(result);
					}
				}
			};
			PlayFabHTTP.Post(PlayFabSettings.GetURL()+"/Client/GetUserStatistics", serializedJSON, "X-Authorization", AuthKey, callback);
		}
Пример #4
0
        public void UserStatisticsApi(UUnitTestContext testContext)
        {
            if (!TITLE_CAN_UPDATE_SETTINGS)
            {
                testContext.EndTest(UUnitFinishState.SKIPPED, "This title cannot update statistics from the client");
                return;
            }

            var getRequest = new GetUserStatisticsRequest();
            PlayFabClientAPI.GetUserStatistics(getRequest, PlayFabUUnitUtils.ApiCallbackWrapper<GetUserStatisticsResult>(testContext, GetUserStatsCallback1), SharedErrorCallback, testContext);
        }
        /// <summary>
        /// Retrieves the details of all title-specific statistics for the user
        /// </summary>
        public static void GetUserStatistics(GetUserStatisticsRequest request, ProcessApiCallback<GetUserStatisticsResult> resultCallback, ErrorCallback errorCallback, object customData = null)
        {
            if (_authKey == null) throw new Exception("Must be logged in to call this method");

            string serializedJson = SimpleJson.SerializeObject(request, Util.ApiSerializerStrategy);
            Action<CallRequestContainer> callback = delegate(CallRequestContainer requestContainer)
            {
                ResultContainer<GetUserStatisticsResult>.HandleResults(requestContainer, resultCallback, errorCallback, null);
            };
            PlayFabHTTP.Post("/Client/GetUserStatistics", serializedJson, "X-Authorization", _authKey, callback, request, customData);
        }
Пример #6
0
        public void UserStatisticsApi()
        {
            int testStatExpected, testStatActual;

            var getRequest = new ClientModels.GetUserStatisticsRequest();
            var getStatTask1 = PlayFabClientAPI.GetUserStatisticsAsync(getRequest);
            getStatTask1.Wait();
            UUnitAssert.Null(getStatTask1.Result.Error, "UserStatistics should have been retrieved from Api call");
            UUnitAssert.NotNull(getStatTask1.Result.Result, "UserStatistics should have been retrieved from Api call");
            UUnitAssert.NotNull(getStatTask1.Result.Result.UserStatistics, "UserStatistics should have been retrieved from Api call");
            if (!getStatTask1.Result.Result.UserStatistics.TryGetValue(TEST_STAT_NAME, out testStatExpected))
                testStatExpected = TEST_STAT_BASE;
            testStatExpected = ((testStatExpected + 1) % TEST_STAT_BASE) + TEST_STAT_BASE; // This test is about the expected value changing (incrementing through from TEST_STAT_BASE to TEST_STAT_BASE * 2 - 1)

            var updateRequest = new ClientModels.UpdateUserStatisticsRequest();
            updateRequest.UserStatistics = new Dictionary<string, int>();
            updateRequest.UserStatistics[TEST_STAT_NAME] = testStatExpected;
            var updateTask = PlayFabClientAPI.UpdateUserStatisticsAsync(updateRequest);
            updateTask.Wait(); // The update doesn't return anything, so can't test anything other than failure

            // Test update result - no data returned, so error or no error, based on Title settings
            if (!TITLE_CAN_UPDATE_SETTINGS)
            {
                UUnitAssert.Null(updateTask.Result.Result, "UpdateStatistics should have failed");
                UUnitAssert.NotNull(updateTask.Result.Error, "UpdateStatistics should have failed");
                return; // The rest of this tests changing settings - Which we verified we cannot do
            }
            else // if (CAN_UPDATE_SETTINGS)
            {
                UUnitAssert.Null(updateTask.Result.Error, "UpdateStatistics call failed");
                UUnitAssert.NotNull(updateTask.Result.Result, "UpdateStatistics call failed");
            }

            getRequest = new ClientModels.GetUserStatisticsRequest();
            var getStatTask2 = PlayFabClientAPI.GetUserStatisticsAsync(getRequest);
            getStatTask2.Wait();
            UUnitAssert.Null(getStatTask2.Result.Error, "UserStatistics should have been retrieved from Api call");
            UUnitAssert.NotNull(getStatTask2.Result.Result, "UserStatistics should have been retrieved from Api call");
            UUnitAssert.NotNull(getStatTask2.Result.Result.UserStatistics, "UserStatistics should have been retrieved from Api call");
            getStatTask2.Result.Result.UserStatistics.TryGetValue(TEST_STAT_NAME, out testStatActual);
            UUnitAssert.Equals(testStatExpected, testStatActual);
        }
Пример #7
0
	void Login(string titleId, string playerName)
	{
		LoginWithCustomIDRequest request = new LoginWithCustomIDRequest()
		{
			TitleId = titleId,
			CreateAccount = true,
			CustomId = playerName
		};

		PlayFabClientAPI.LoginWithCustomID(request,(result)=>
		{
			PlayFabId = result.PlayFabId;
			Debug.Log ("Got PlayFabId: " + PlayFabId);

			if(result.NewlyCreated)
			{
				Debug.Log ("New account");
			}
			else
			{
				Debug.Log ("Existing account");
			}
			GetUserStatisticsRequest req = new GetUserStatisticsRequest();
			PlayFabClientAPI.GetUserStatistics(req, OnGetSuccess, onPlayFabError, null);
		},
		(ErrorCallback) =>
		{
			Debug.Log ("Error creating/logging on account");
		});
	}
Пример #8
0
        public void UserStatisticsApi()
        {
            int testStatExpected, testStatActual;

            var getRequest = new GetUserStatisticsRequest();
            PlayFabClientAPI.GetUserStatistics(getRequest, GetUserStatsCallback, SharedErrorCallback);
            WaitForApiCalls();

            UUnitAssert.Equals("User Stats Received", lastReceivedMessage);
            testStatExpected = ((testStatReturn + 1) % TEST_STAT_BASE) + TEST_STAT_BASE; // This test is about the expected value changing (incrementing through from TEST_STAT_BASE to TEST_STAT_BASE * 2 - 1)

            var updateRequest = new UpdateUserStatisticsRequest();
            updateRequest.UserStatistics = new Dictionary<string, int>();
            updateRequest.UserStatistics[TEST_STAT_NAME] = testStatExpected;
            PlayFabClientAPI.UpdateUserStatistics(updateRequest, UpdateUserStatsCallback, SharedErrorCallback);
            WaitForApiCalls();

            // Test update result - no data returned, so error or no error, based on Title settings
            if (!TITLE_CAN_UPDATE_SETTINGS)
            {
                UUnitAssert.Equals("error message from PlayFab", lastReceivedMessage);
                return; // The rest of this tests changing settings - Which we verified we cannot do
            }
            else // if (CAN_UPDATE_SETTINGS)
            {
                UUnitAssert.Equals("User Stats Updated", lastReceivedMessage);
            }

            getRequest = new GetUserStatisticsRequest();
            PlayFabClientAPI.GetUserStatistics(getRequest, GetUserStatsCallback, SharedErrorCallback);
            WaitForApiCalls();

            UUnitAssert.Equals("User Stats Received", lastReceivedMessage);
            testStatActual = testStatReturn;
            UUnitAssert.Equals(testStatExpected, testStatActual);
        }
Пример #9
0
		/// <summary>
		/// Retrieves the details of all title-specific statistics for the user
		/// </summary>
        public static async Task<PlayFabResult<GetUserStatisticsResult>> GetUserStatisticsAsync(GetUserStatisticsRequest request)
        {
            if (AuthKey == null) throw new Exception ("Must be logged in to call this method");

            object httpResult = await PlayFabHTTP.DoPost(PlayFabSettings.GetURL() + "/Client/GetUserStatistics", request, "X-Authorization", AuthKey);
            if(httpResult is PlayFabError)
            {
                PlayFabError error = (PlayFabError)httpResult;
                if (PlayFabSettings.GlobalErrorHandler != null)
                    PlayFabSettings.GlobalErrorHandler(error);
                return new PlayFabResult<GetUserStatisticsResult>
                {
                    Error = error,
                };
            }
            string resultRawJson = (string)httpResult;

            var serializer = JsonSerializer.Create(PlayFabSettings.JsonSettings);
            var resultData = serializer.Deserialize<PlayFabJsonSuccess<GetUserStatisticsResult>>(new JsonTextReader(new StringReader(resultRawJson)));
			
			GetUserStatisticsResult result = resultData.data;
			
			
            return new PlayFabResult<GetUserStatisticsResult>
                {
                    Result = result
                };
        }
 /// <summary>
 /// Method used to get user statistics from PlayFab.
 /// </summary>
 public void GetUserStatistics()
 {
     GetUserStatisticsRequest request = new GetUserStatisticsRequest();
     PlayFabClientAPI.GetUserStatistics(request, OnUserStatisticsLoaded, OnGetUserStatisticsError);
 }
//	public void UpdatePlayerXP(int xp) {
//		UpdateUserDataRequest updateReq = new UpdateUserDataRequest ();
//		updateReq.Data = new System.Collections.Generic.Dictionary<string, string> ();
//		updateReq.Data.Add("XP", xp.ToString());
//		PlayFabClientAPI.UpdateUserData (updateReq, OnUpdatePlayerXPSuccess, OnPlayFabError);
//	}

//	private IEnumerator GetPlayerData(float sec = 0) {
//		yield return new WaitForSeconds (sec);
//		GetUserCombinedInfoRequest infoReq = new GetUserCombinedInfoRequest ();
//		PlayFabClientAPI.GetUserCombinedInfo (infoReq, OnPlayFabGetUserInfo, OnPlayFabError);
//	}

	private IEnumerator CoGetPlayerXP(float sec = 0) {
		yield return new WaitForSeconds (sec);
		GetUserStatisticsRequest xpReq = new GetUserStatisticsRequest ();
		PlayFabClientAPI.GetUserStatistics (xpReq, OnPlayFabGetUserStatistics, OnPlayFabError);
	}