/// <summary>
        /// Retrieves a list of ranked users for the given statistic, centered on the currently signed-in user
        /// </summary>
        public static void GetLeaderboardAroundCurrentUser(GetLeaderboardAroundCurrentUserRequest request, ProcessApiCallback<GetLeaderboardAroundCurrentUserResult> 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<GetLeaderboardAroundCurrentUserResult>.HandleResults(requestContainer, resultCallback, errorCallback, null);
            };
            PlayFabHTTP.Post("/Client/GetLeaderboardAroundCurrentUser", serializedJson, "X-Authorization", _authKey, callback, request, customData);
        }
示例#2
0
		/// <summary>
		/// Retrieves a list of ranked users for the given statistic, centered on the currently signed-in user
		/// </summary>
		public static void GetLeaderboardAroundCurrentUser(GetLeaderboardAroundCurrentUserRequest request, GetLeaderboardAroundCurrentUserCallback 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)
			{
				GetLeaderboardAroundCurrentUserResult result = null;
				PlayFabError error = null;
				ResultContainer<GetLeaderboardAroundCurrentUserResult>.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/GetLeaderboardAroundCurrentUser", serializedJSON, "X-Authorization", AuthKey, callback);
		}
示例#3
0
        public void LeaderBoard()
        {
            var clientRequest = new ClientModels.GetLeaderboardAroundCurrentUserRequest();
            clientRequest.MaxResultsCount = 3;
            clientRequest.StatisticName = TEST_STAT_NAME;
            var clientTask = PlayFabClientAPI.GetLeaderboardAroundCurrentUserAsync(clientRequest);
            clientTask.Wait();
            UUnitAssert.Null(clientTask.Result.Error, "Failed to get client leaderboard");
            UUnitAssert.NotNull(clientTask.Result.Result, "Failed to get client leaderboard");
            UUnitAssert.NotNull(clientTask.Result.Result.Leaderboard, "Failed to get client leaderboard");
            UUnitAssert.True(clientTask.Result.Result.Leaderboard.Count > 0, "Leaderboard does not contain enough entries.");

            var serverRequest = new ServerModels.GetLeaderboardAroundCharacterRequest();
            serverRequest.MaxResultsCount = 3;
            serverRequest.StatisticName = TEST_STAT_NAME;
            serverRequest.CharacterId = characterId;
            serverRequest.PlayFabId = playFabId;
            var serverTask = PlayFabServerAPI.GetLeaderboardAroundCharacterAsync(serverRequest);
            clientTask.Wait();
            UUnitAssert.Null(serverTask.Result.Error, "Failed to get server leaderboard");
            UUnitAssert.NotNull(serverTask.Result.Result, "Failed to get server leaderboard");
            UUnitAssert.NotNull(serverTask.Result.Result.Leaderboard, "Failed to get server leaderboard");
            UUnitAssert.True(serverTask.Result.Result.Leaderboard.Count > 0, "Leaderboard does not contain enough entries.");
        }
示例#4
0
		/// <summary>
		/// Retrieves a list of ranked users for the given statistic, centered on the currently signed-in user
		/// </summary>
        public static async Task<PlayFabResult<GetLeaderboardAroundCurrentUserResult>> GetLeaderboardAroundCurrentUserAsync(GetLeaderboardAroundCurrentUserRequest request)
        {
            if (AuthKey == null) throw new Exception ("Must be logged in to call this method");

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

            var serializer = JsonSerializer.Create(PlayFabSettings.JsonSettings);
            var resultData = serializer.Deserialize<PlayFabJsonSuccess<GetLeaderboardAroundCurrentUserResult>>(new JsonTextReader(new StringReader(resultRawJson)));
			
			GetLeaderboardAroundCurrentUserResult result = resultData.data;
			
			
            return new PlayFabResult<GetLeaderboardAroundCurrentUserResult>
                {
                    Result = result
                };
        }
        public void LeaderBoard()
        {
            var clientRequest = new ClientModels.GetLeaderboardAroundCurrentUserRequest();
            clientRequest.MaxResultsCount = 3;
            clientRequest.StatisticName = TEST_STAT_NAME;
            var clientTask = Client.GetLeaderboardAroundCurrentUserAsync(clientRequest);
            try
            {
                clientTask.Wait();
            }
            catch(Exception ex)
            {
                UUnitAssert.True(false, ex.Message);
            }
            UUnitAssert.NotNull(clientTask.Result, "Failed to get client leaderboard");
            UUnitAssert.True(clientTask.Result.Count > 0, "Leaderboard does not contain enough entries.");

            var serverRequest = new ServerModels.GetLeaderboardAroundCharacterRequest();
            serverRequest.MaxResultsCount = 3;
            serverRequest.StatisticName = TEST_STAT_NAME;
            serverRequest.CharacterId = characterId;
            serverRequest.PlayFabId = playFabId;
            var serverTask = Server.GetLeaderboardAroundCharacterAsync(serverRequest);

            try
            {
                clientTask.Wait();
            }
            catch (Exception ex)
            {
                UUnitAssert.True(false, ex.Message);
            }
            UUnitAssert.NotNull(serverTask.Result, "Failed to get server leaderboard");
            UUnitAssert.True(serverTask.Result.Count > 0, "Leaderboard does not contain enough entries.");
        }
    /// <summary>
    /// Method used to get a defined number of users around the current user, based on a defined stat.
    /// </summary>
    /// <param name="property">Property to define the leaderboard.</param>
    /// <param name="maxResults">Maximum number of players to return.</param>
    /// <param name="OnLeaberboardLoaded">Callback when the leaderboard is loaded.</param>
    public void GetLeaderboardAroundMe(string property, int maxResults, ProjectDelegates.PlayFabLeaderboardCallback OnLeaberboardLoaded)
    {
        OnLeaderboardLoadedCallback = OnLeaberboardLoaded;

        GetLeaderboardAroundCurrentUserRequest request = new GetLeaderboardAroundCurrentUserRequest();
        request.StatisticName = property;
        request.MaxResultsCount = maxResults;

        PlayFabClientAPI.GetLeaderboardAroundCurrentUser(request, OnGetLeaderboardAroundMeResult, OnGetLeaderboardError);
    }
	public void GetLeaderBoard_UserData(){
		
		GetLeaderboardAroundCurrentUserRequest request = new GetLeaderboardAroundCurrentUserRequest () {
			StatisticName = Setting_Manager.HIGH_SCORE_KEY,
			MaxResultsCount = 10,
		//	StartPosition = 0
		};
		PlayFabClientAPI.GetLeaderboardAroundCurrentUser (request, (result) => {
			Debug.Log ("Got leaderboard user data:");
			if ((result.Leaderboard == null) || (result.Leaderboard.Count == 0)) {
				Debug.Log ("No leaderboard user data available");
			} else {
				for (int i=0;i<10;i++){
					if (i < result.Leaderboard.Count){
						Debug.Log(result.Leaderboard[i].DisplayName);
						Debug.Log(result.Leaderboard[i].Position);
						Debug.Log(result.Leaderboard[i].PlayFabId);
						if (result.Leaderboard[i].PlayFabId == CustomIDLogin){
							Setting_Manager.sInstance.PlayerRank = result.Leaderboard[i].Position;
						}
					}
				}
			}
		}, (error) => {
			Debug.Log ("Got error retrieving leaderboard user data:");
			Debug.Log (error.ErrorMessage);
		});

	}