public string getUserName()
    {
        LeaderboardScoreData data = new LeaderboardScoreData(LeaderBoardID);
        string username           = data.PlayerScore.userID;

        return(username);
    }
        /// <summary>
        /// Handles the fetch of a specific leaderboard definition.  This
        /// is called with the expectation that the leaderboard summary and
        /// scores are also needed.
        /// </summary>
        /// <param name="token">token for the current fetching request.</param>
        /// <param name="response">Response.</param>
        /// <param name="selfPlayerId">Self player identifier.</param>
        /// <param name="maxResults">Number of scores to return.</param>
        /// <param name="callback">Callback.</param>
        internal void HandleFetch(ScorePageToken token,
                                  FetchResponse response,
                                  string selfPlayerId,
                                  int maxResults,
                                  Action <LeaderboardScoreData> callback)
        {
            LeaderboardScoreData data =
                new LeaderboardScoreData(
                    token.LeaderboardId, (ResponseStatus)response.GetStatus());

            if (response.GetStatus() != Status.ResponseStatus.VALID &&
                response.GetStatus() != Status.ResponseStatus.VALID_BUT_STALE)
            {
                Logger.w("Error returned from fetch: " + response.GetStatus());
                callback(data);
                return;
            }

            data.Title = response.Leaderboard().Title();
            data.Id    = token.LeaderboardId;

            // now fetch the summary of the leaderboard.

            C.LeaderboardManager_FetchScoreSummary(mServices.AsHandle(),
                                                   Types.DataSource.CACHE_OR_NETWORK,
                                                   token.LeaderboardId,
                                                   (Types.LeaderboardTimeSpan)token.TimeSpan,
                                                   (Types.LeaderboardCollection)token.Collection,
                                                   InternalFetchSummaryCallback,
                                                   Callbacks.ToIntPtr <FetchScoreSummaryResponse>((rsp) =>
                                                                                                  HandleFetchScoreSummary(data, rsp, selfPlayerId, maxResults, token, callback),
                                                                                                  FetchScoreSummaryResponse.FromPointer)
                                                   );
        }
        internal void DoLoadMoreScores()
        {
            if (mScoreData == null)
            {
                mStatus = "mScoreData is null.";
                return;
            }

            PlayGamesPlatform.Instance.LoadMoreScores(mScoreData.NextPageToken, 10,
                                                      (data) =>
            {
                if (data.Status == ResponseStatus.InternalError)
                {
                    mStatus    = "Internal error";
                    mScoreData = null;
                }
                else
                {
                    mStatus    = "LB data Status: " + data.Status;
                    mStatus   += " valid: " + data.Valid;
                    mStatus   += "\n approx:" + data.ApproximateCount + " have " + data.Scores.Length;
                    mScoreData = data;
                }
            }
                                                      );
        }
        internal void HandleFetchScoreSummary(LeaderboardScoreData data,
                                              FetchScoreSummaryResponse response,
                                              string selfPlayerId, int maxResults,
                                              ScorePageToken token, Action <LeaderboardScoreData> callback)
        {
            if (response.GetStatus() != Status.ResponseStatus.VALID &&
                response.GetStatus() != Status.ResponseStatus.VALID_BUT_STALE)
            {
                Logger.w("Error returned from fetchScoreSummary: " + response);
                data.Status = (ResponseStatus)response.GetStatus();
                callback(data);
                return;
            }

            NativeScoreSummary summary = response.GetScoreSummary();

            data.ApproximateCount = summary.ApproximateResults();
            data.PlayerScore      = summary.LocalUserScore().AsScore(data.Id, selfPlayerId);


            // if the maxResults is 0, no scores are needed, so we are done.
            if (maxResults <= 0)
            {
                callback(data);
                return;
            }

            LoadScorePage(data, maxResults, token, callback);
        }
Beispiel #5
0
        internal void HandleFetchScorePage(LeaderboardScoreData data, ScorePageToken token, FetchScorePageResponse rsp, Action <LeaderboardScoreData> callback)
        {
            data.Status = (GooglePlayGames.BasicApi.ResponseStatus)rsp.GetStatus();
            if (rsp.GetStatus() != CommonErrorStatus.ResponseStatus.VALID && rsp.GetStatus() != CommonErrorStatus.ResponseStatus.VALID_BUT_STALE)
            {
                callback(data);
            }
            NativeScorePage scorePage = rsp.GetScorePage();

            if (!scorePage.Valid())
            {
                callback(data);
            }
            if (scorePage.HasNextScorePage())
            {
                data.NextPageToken = new ScorePageToken((object)scorePage.GetNextScorePageToken(), token.LeaderboardId, token.Collection, token.TimeSpan);
            }
            if (scorePage.HasPrevScorePage())
            {
                data.PrevPageToken = new ScorePageToken((object)scorePage.GetPreviousScorePageToken(), token.LeaderboardId, token.Collection, token.TimeSpan);
            }
            foreach (NativeScoreEntry nativeScoreEntry in scorePage)
            {
                data.AddScore(nativeScoreEntry.AsScore(data.Id));
            }
            callback(data);
        }
Beispiel #6
0
 public void LoadScorePage(LeaderboardScoreData data, int maxResults, ScorePageToken token, Action <LeaderboardScoreData> callback)
 {
     if (data == null)
     {
         data = new LeaderboardScoreData(token.LeaderboardId);
     }
     GooglePlayGames.Native.Cwrapper.LeaderboardManager.LeaderboardManager_FetchScorePage(this.mServices.AsHandle(), Types.DataSource.CACHE_OR_NETWORK, ((BaseReferenceHolder)token.InternalObject).AsPointer(), (uint)maxResults, new GooglePlayGames.Native.Cwrapper.LeaderboardManager.FetchScorePageCallback(LeaderboardManager.InternalFetchScorePage), Callbacks.ToIntPtr <FetchScorePageResponse>((Action <FetchScorePageResponse>)(rsp => this.HandleFetchScorePage(data, token, rsp, callback)), new Func <IntPtr, FetchScorePageResponse>(FetchScorePageResponse.FromPointer)));
 }
Beispiel #7
0
        private LeaderboardScoreData CreateLeaderboardScoreData(
            string leaderboardId,
            LeaderboardCollection collection,
            LeaderboardTimeSpan timespan,
            ResponseStatus status,
            AndroidJavaObject leaderboardScoresJava)
        {
            LeaderboardScoreData leaderboardScoreData = new LeaderboardScoreData(leaderboardId, status);
            var scoresBuffer = leaderboardScoresJava.Call <AndroidJavaObject>("getScores");
            int count        = scoresBuffer.Call <int>("getCount");

            for (int i = 0; i < count; ++i)
            {
                using (var leaderboardScore = scoresBuffer.Call <AndroidJavaObject>("get", i))
                {
                    long            timestamp = leaderboardScore.Call <long>("getTimestampMillis");
                    System.DateTime date      = AndroidJavaConverter.ToDateTime(timestamp);

                    ulong  rank          = (ulong)leaderboardScore.Call <long>("getRank");
                    string scoreHolderId = "";
                    using (var scoreHolder = leaderboardScore.Call <AndroidJavaObject>("getScoreHolder"))
                    {
                        scoreHolderId = scoreHolder.Call <string>("getPlayerId");
                    }

                    ulong  score    = (ulong)leaderboardScore.Call <long>("getRawScore");
                    string metadata = leaderboardScore.Call <string>("getScoreTag");

                    leaderboardScoreData.AddScore(new PlayGamesScore(date, leaderboardId,
                                                                     rank, scoreHolderId, score, metadata));
                }
            }

            leaderboardScoreData.NextPageToken = new ScorePageToken(scoresBuffer, leaderboardId, collection,
                                                                    timespan, ScorePageDirection.Forward);
            leaderboardScoreData.PrevPageToken = new ScorePageToken(scoresBuffer, leaderboardId, collection,
                                                                    timespan, ScorePageDirection.Backward);

            using (var leaderboard = leaderboardScoresJava.Call <AndroidJavaObject>("getLeaderboard"))
                using (var variants = leaderboard.Call <AndroidJavaObject>("getVariants"))
                    using (var variant = variants.Call <AndroidJavaObject>("get", 0))
                    {
                        leaderboardScoreData.Title = leaderboard.Call <string>("getDisplayName");
                        if (variant.Call <bool>("hasPlayerInfo"))
                        {
                            System.DateTime date     = AndroidJavaConverter.ToDateTime(0);
                            ulong           rank     = (ulong)variant.Call <long>("getPlayerRank");
                            ulong           score    = (ulong)variant.Call <long>("getRawPlayerScore");
                            string          metadata = variant.Call <string>("getPlayerScoreTag");
                            leaderboardScoreData.PlayerScore = new PlayGamesScore(date, leaderboardId,
                                                                                  rank, mUser.id, score, metadata);
                        }

                        leaderboardScoreData.ApproximateCount = (ulong)variant.Call <long>("getNumScores");
                    }

            return(leaderboardScoreData);
        }
Beispiel #8
0
 // Get Next Leaderboard Page
 public void GetNextPage(LeaderboardScoreData data)
 {
     PlayGamesPlatform.Instance.LoadMoreScores(data.NextPageToken, 10,
                                               (results) =>
     {
         mStatus  = "Leaderboard data valid: " + data.Valid;
         mStatus += "\n approx:" + data.ApproximateCount + " have " + data.Scores.Length;
     });
 }
        private static IEnumerator GetLeaderboardPlayers(LeaderboardScoreData scoreData,
                                                         Action <List <UserProfile> > callback)
        {
            if (!scoreData.Valid ||
                (scoreData.Status != ResponseStatus.Success &&
                 scoreData.Status != ResponseStatus.SuccessWithStale))
            {
                Debug.Log("DEBUG+: Valid: " + scoreData.Valid + ", Status: " + scoreData.Status);
                yield break;
            }

            Debug.Log("DEBUG+: Scores loaded successful!");

            var scores = new List <IScore>();

            scores.AddRange(scoreData.Scores);

            for (var i = 0; i < 3; i++)
            {
                PlayGamesPlatform.Instance.LoadMoreScores(scoreData.NextPageToken, 25, nextScoreData =>
                {
                    if (nextScoreData.Valid &&
                        (nextScoreData.Status == ResponseStatus.Success ||
                         nextScoreData.Status == ResponseStatus.SuccessWithStale))
                    {
                        scores.AddRange(nextScoreData.Scores);
                    }
                });
            }

            var usersProfiles = new List <UserProfile>();
            var usersIDs      = new List <string>(scores.Select(score => score.userID));

            yield return(LoadUsersByIds(usersIDs.ToArray(), users => { usersProfiles = users; }));

            for (var i = 0; i < usersProfiles.Count; i++)
            {
                var user = usersProfiles[i];

                if (user.Id == scoreData.Scores[i].userID)
                {
                    user.Score = scoreData.Scores[i].value;
                    user.Place = scoreData.Scores[i].rank;

                    if (user.Id == PlayGamesPlatform.Instance.localUser.id)
                    {
                        LeaderboardEventSystem.Instance.UserLoaded(user);
                    }
                }
            }

            callback.Invoke(usersProfiles);
        }
        public void LoadScorePage(LeaderboardScoreData data, int maxResults, ScorePageToken token, Action <LeaderboardScoreData> callback)
        {
            if (data == null)
            {
                data = new LeaderboardScoreData(token.LeaderboardId);
            }
            NativeScorePageToken nativeScorePageToken = (NativeScorePageToken)token.InternalObject;

            GooglePlayGames.Native.Cwrapper.LeaderboardManager.LeaderboardManager_FetchScorePage(mServices.AsHandle(), Types.DataSource.CACHE_OR_NETWORK, nativeScorePageToken.AsPointer(), (uint)maxResults, InternalFetchScorePage, Callbacks.ToIntPtr(delegate(FetchScorePageResponse rsp)
            {
                HandleFetchScorePage(data, token, rsp, callback);
            }, FetchScorePageResponse.FromPointer));
        }
        internal void HandleLoadingScores(PlayGamesLeaderboard board, LeaderboardScoreData scoreData, Action <bool> callback)
        {
            bool flag = board.SetFromData(scoreData);

            if (flag && !board.HasAllScores() && scoreData.NextPageToken != null)
            {
                int rowCount = board.range.count - board.ScoreCount;
                this.mClient.LoadMoreScores(scoreData.NextPageToken, rowCount, (Action <LeaderboardScoreData>)(nextScoreData => this.HandleLoadingScores(board, nextScoreData, callback)));
            }
            else
            {
                callback(flag);
            }
        }
Beispiel #12
0
    public static void OnAndroidDataRetrieved(LeaderboardScoreData data, Action <LeaderboardData> OnComplete)
    {
        LeaderboardData lb = new LeaderboardData();

        if (data.Valid)
        {
            IScore curScore = data.Scores[0];
            lb.init     = true;
            lb.round    = curScore.value;
            lb.position = curScore.rank;
            Debug.Log("curScore.rank");
        }

        OnComplete(lb);
    }
 internal void DoSocialLoadScores()
 {
     PlayGamesPlatform.Instance.LoadScores(
         GPGSIds.leaderboard_leaders_in_smoketesting,
         LeaderboardStart.PlayerCentered,
         /* rowCount= */ 25,
         LeaderboardCollection.Social,
         LeaderboardTimeSpan.AllTime,
         (data) =>
     {
         mStatus    = "Leaderboard data valid: " + data.Valid;
         mStatus   += "\n approx:" + data.ApproximateCount + " have " + data.Scores.Length;
         mScoreData = data;
     });
 }
 internal bool SetFromData(LeaderboardScoreData data)
 {
     if (data.Valid)
     {
         Debug.Log("Setting leaderboard from: " + data);
         this.SetMaxRange(data.ApproximateCount);
         this.SetTitle(data.Title);
         this.SetLocalUserScore((PlayGamesScore)data.PlayerScore);
         foreach (IScore score in data.Scores)
         {
             this.AddScore((PlayGamesScore)score);
         }
         this.mLoading = (data.Scores.Length == 0) || this.HasAllScores();
     }
     return(data.Valid);
 }
Beispiel #15
0
    private void OnScoresLoaded(LeaderboardScoreData leaderboardScoreData)
    {
        var scores = leaderboardScoreData.Scores;

        if (scores == null)
        {
            Debug.LogWarning("No scores");
            ScoresFinished = true;
        }
        else
        {
            Debug.Log("Got scores");
            Scores = scores;
            PlayGamesPlatform.Instance.LoadUsers(Scores.Select(s => s.userID).ToArray(), OuUsersLoaded);
        }
    }
 internal bool SetFromData(LeaderboardScoreData data)
 {
     if (data.Valid)
     {
         Debug.Log((object)("Setting leaderboard from: " + data));
         SetMaxRange(data.ApproximateCount);
         SetTitle(data.Title);
         SetLocalUserScore((PlayGamesScore)data.PlayerScore);
         IScore[] scores = data.Scores;
         foreach (IScore val in scores)
         {
             AddScore((PlayGamesScore)val);
         }
         mLoading = (data.Scores.Length == 0 || HasAllScores());
     }
     return(data.Valid);
 }
        internal bool SetFromData(LeaderboardScoreData data)
        {
            if (data.Valid)
            {
                OurUtils.Logger.d("Setting leaderboard from: " + data);
                SetMaxRange(data.ApproximateCount);
                SetTitle(data.Title);
                SetLocalUserScore((PlayGamesScore)data.PlayerScore);
                foreach (IScore score in data.Scores)
                {
                    AddScore((PlayGamesScore)score);
                }

                mLoading = data.Scores.Length == 0 || HasAllScores();
            }

            return(data.Valid);
        }
        internal void HandleLoadingScores(PlayGamesLeaderboard board,
            LeaderboardScoreData scoreData, Action<bool> callback)
        {
            bool ok = board.SetFromData(scoreData);
            if (ok && !board.HasAllScores() && scoreData.NextPageToken != null)
            {
                int rowCount = board.range.count - board.ScoreCount;

                // need to load more scores
                mClient.LoadMoreScores(scoreData.NextPageToken, rowCount,
                    (nextScoreData) =>
                    HandleLoadingScores(board, nextScoreData, callback));
            }
            else
            {
                callback(ok);
            }
        }
        internal void HandleFetch(ScorePageToken token, FetchResponse response, string selfPlayerId, int maxResults, Action <LeaderboardScoreData> callback)
        {
            LeaderboardScoreData data = new LeaderboardScoreData(token.LeaderboardId, (ResponseStatus)response.GetStatus());

            if (response.GetStatus() != CommonErrorStatus.ResponseStatus.VALID && response.GetStatus() != CommonErrorStatus.ResponseStatus.VALID_BUT_STALE)
            {
                Logger.w("Error returned from fetch: " + response.GetStatus());
                callback(data);
            }
            else
            {
                data.Title = response.Leaderboard().Title();
                data.Id    = token.LeaderboardId;
                GooglePlayGames.Native.Cwrapper.LeaderboardManager.LeaderboardManager_FetchScoreSummary(mServices.AsHandle(), Types.DataSource.CACHE_OR_NETWORK, token.LeaderboardId, (Types.LeaderboardTimeSpan) token.TimeSpan, (Types.LeaderboardCollection) token.Collection, InternalFetchSummaryCallback, Callbacks.ToIntPtr(delegate(FetchScoreSummaryResponse rsp)
                {
                    HandleFetchScoreSummary(data, rsp, selfPlayerId, maxResults, token, callback);
                }, FetchScoreSummaryResponse.FromPointer));
            }
        }
        internal void HandleFetchScorePage(LeaderboardScoreData data,
                                           ScorePageToken token,
                                           FetchScorePageResponse rsp, Action <LeaderboardScoreData> callback)
        {
            data.Status = (ResponseStatus)rsp.GetStatus();
            // add the scores that match the criteria
            if (rsp.GetStatus() != Status.ResponseStatus.VALID &&
                rsp.GetStatus() != Status.ResponseStatus.VALID_BUT_STALE)
            {
                callback(data);
            }

            NativeScorePage page = rsp.GetScorePage();

            if (!page.Valid())
            {
                callback(data);
            }

            if (page.HasNextScorePage())
            {
                data.NextPageToken = new ScorePageToken(
                    page.GetNextScorePageToken(),
                    token.LeaderboardId,
                    token.Collection,
                    token.TimeSpan);
            }
            if (page.HasPrevScorePage())
            {
                data.PrevPageToken = new ScorePageToken(
                    page.GetPreviousScorePageToken(),
                    token.LeaderboardId,
                    token.Collection,
                    token.TimeSpan);
            }

            foreach (NativeScoreEntry ent in page)
            {
                data.AddScore(ent.AsScore(data.Id));
            }

            callback(data);
        }
        internal void HandleLoadingScores(PlayGamesLeaderboard board, LeaderboardScoreData scoreData, Action <bool> callback)
        {
            //IL_004f: Unknown result type (might be due to invalid IL or missing references)
            //IL_0054: Unknown result type (might be due to invalid IL or missing references)
            bool flag = board.SetFromData(scoreData);

            if (flag && !board.HasAllScores() && scoreData.NextPageToken != null)
            {
                Range range    = board.range;
                int   rowCount = range.count - board.ScoreCount;
                mClient.LoadMoreScores(scoreData.NextPageToken, rowCount, delegate(LeaderboardScoreData nextScoreData)
                {
                    HandleLoadingScores(board, nextScoreData, callback);
                });
            }
            else
            {
                callback(flag);
            }
        }
Beispiel #22
0
    private void OnUserSignedOut()
    {
        PlayerPrefs.SetInt("GPGS_SignInState", 0); // Once signed out, do not auto sign-in next time.
        userSignedIn = false;
        UpdateSignedInUI();

        if (initPlayServices)
        {
            // Clear leaderboard state.
            leaderboardData          = null;
            curLeaderboardIndex      = 0;
            leaderboardPageCount     = 0;
            leaderboardListLoadState = LeaderboardLoadState.DoneLoading;
            leaderboardUserLoadState = LeaderboardLoadState.DoneLoading;

            // Reset dropdown selections for leaderboards.
            leaderboardTimeFrame.SelectItem(2);  // All Time.
            leaderboardCollection.SelectItem(0); // Global.
        }
    }
 private void LoadLeaderboardData_Handler(LeaderboardScoreData data)
 {
     Debug.Log("LoadLeaderboardData");
     Debug.Log($"Valid: [{data.Valid}]");
     if (data != null)
     {
         if (data.Scores.Length == 0)
         {
             Debug.Log("Score Lenght == 0");
         }
         foreach (var score in data.Scores)
         {
             Debug.Log($"Date: [{score.date}]; UserID: [{score.userID}]; Value: [{score.value}]");
         }
     }
     else
     {
         Debug.Log("Load data flom leadeboard [DATA IS NULL]");
     }
 }
Beispiel #24
0
    // Initialize Play Services variables upon login.
    private void InitializeServicesVariables()
    {
        if (initPlayServices)
        {
            return;
        }

        initPlayServices             = true;
        highestSubmittedScores       = new Dictionary <string, long>();
        leaderboardData              = null;
        curLeaderboardIndex          = 0;
        leaderboardListLoadState     = LeaderboardLoadState.DoneLoading;
        leaderboardUserLoadState     = LeaderboardLoadState.DoneLoading;
        leaderboardCollectionSetting = LeaderboardCollection.Public;
        leaderboardTimeSpanSetting   = LeaderboardTimeSpan.AllTime;

        // Initialize data instances for each entry in a page.
        leaderboardResults   = new LeaderboardResult[LEADERBOARD_ENTRIES_PER_PAGE];
        leaderboardListUi    = new LeaderboardItemUI[LEADERBOARD_ENTRIES_PER_PAGE];
        leaderboardPageCount = 0;
        curUserFilter        = new string[1] {
            PlayGamesPlatform.Instance.localUser.id
        };

        // Configure dropdowns for leaderboards.
        leaderboardTimeFrame.ForceItems("Today", "This Week", "All Time");
        leaderboardCollection.ForceItems("Global", "Friends");
        leaderboardTimeFrame.SelectItem(2);  // All Time.
        leaderboardCollection.SelectItem(0); // Global.

        for (int i = 0; i < LEADERBOARD_ENTRIES_PER_PAGE; i++)
        {
            leaderboardResults[i] = new LeaderboardResult();

            leaderboardListUi[i] = SetupLeaderboardListItem(leaderboardListStart);
            leaderboardListUi[i].cachedGo.SetActive(false);
        }

        curUserLeaderboardItem = SetupLeaderboardListItem(leaderboardCurPlayerStart);
        curUserLeaderboardItem.cachedGo.SetActive(false);
    }
Beispiel #25
0
 internal void HandleFetchScoreSummary(LeaderboardScoreData data, FetchScoreSummaryResponse response, string selfPlayerId, int maxResults, ScorePageToken token, Action <LeaderboardScoreData> callback)
 {
     if (response.GetStatus() != CommonErrorStatus.ResponseStatus.VALID && response.GetStatus() != CommonErrorStatus.ResponseStatus.VALID_BUT_STALE)
     {
         Logger.w("Error returned from fetchScoreSummary: " + (object)response);
         data.Status = (GooglePlayGames.BasicApi.ResponseStatus)response.GetStatus();
         callback(data);
     }
     else
     {
         NativeScoreSummary scoreSummary = response.GetScoreSummary();
         data.ApproximateCount = scoreSummary.ApproximateResults();
         data.PlayerScore      = (IScore)scoreSummary.LocalUserScore().AsScore(data.Id, selfPlayerId);
         if (maxResults <= 0)
         {
             callback(data);
         }
         else
         {
             this.LoadScorePage(data, maxResults, token, callback);
         }
     }
 }
Beispiel #26
0
 internal void HandleLoadingScores(PlayGamesLeaderboard board, LeaderboardScoreData scoreData, Action <bool> callback)
 {