Beispiel #1
0
        static void DoNextLoadScoreRequest()
        {
            LoadScoreRequest request;

            if (isLoadingScore)
            {
                return;
            }

            if (loadScoreRequests.Count == 0)
            {
                return;
            }

            isLoadingScore = true;
            request        = loadScoreRequests[0]; // fetch the next request
            loadScoreRequests.RemoveAt(0);         // then remove it from the queue

            // Now create a new leaderboard and start loading scores
            ILeaderboard ldb = Social.CreateLeaderboard();

            ldb.id = request.leaderboardId;

            if (request.useLeaderboardDefault)
            {
                // The current iOS implementation of ISocialPlatform behaves weirdly with Social.LoadScores.
                // Experiment showed that only the first score on the leaderboard was returned.
                // On Android scores were returned properly.
                // We'll have different code for the two platforms in an attempt to provide consistent behavior from the outside.
#if UNITY_ANDROID
                // On Android, we'll use LoadScores directly from Social.
                Social.LoadScores(ldb.id, (IScore[] scores) =>
                {
                    if (request.callback != null)
                    {
                        request.callback(request.leaderboardName, scores);
                    }

                    // Load next request
                    isLoadingScore = false;
                    DoNextLoadScoreRequest();
                });
#elif UNITY_IOS
                // On iOS, we use LoadScores from ILeaderboard with default parameters.
                ldb.LoadScores((bool success) =>
                {
                    if (request.callback != null)
                    {
                        request.callback(request.leaderboardName, ldb.scores);
                    }

                    // Load next request
                    isLoadingScore = false;
                    DoNextLoadScoreRequest();
                });
#endif
            }
            else
            {
                ldb.timeScope = request.timeScope;
                ldb.userScope = request.userScope;

                if (request.fromRank > 0 && request.scoreCount > 0)
                {
                    ldb.range = new Range(request.fromRank, request.scoreCount);
                }

                ldb.LoadScores((bool success) =>
                {
                    if (request.loadLocalUserScore)
                    {
                        IScore[] returnScores = new IScore[] { ldb.localUserScore };

                        if (request.callback != null)
                        {
                            request.callback(request.leaderboardName, returnScores);
                        }
                    }
                    else
                    {
                        if (request.callback != null)
                        {
                            request.callback(request.leaderboardName, ldb.scores);
                        }
                    }

                    // Load next request
                    isLoadingScore = false;
                    DoNextLoadScoreRequest();
                });
            }
        }
 /// <summary>
 /// Get the leaderboard.
 /// </summary>
 void DoLeaderboard()
 {
     m_Leaderboard    = Social.CreateLeaderboard();
     m_Leaderboard.id = leaderboardID;  // YOUR CUSTOM LEADERBOARD NAME
     m_Leaderboard.LoadScores(result => DidLoadLeaderboard(result));
 }