internal ScorePageToken(object internalObject, string id,
     LeaderboardCollection collection, LeaderboardTimeSpan timespan)
 {
     mInternalObject = internalObject;
     mId = id;
     mCollection = collection;
     mTimespan = timespan;
 }
        internal void ShowUI(string leaderboardId, 
            LeaderboardTimeSpan span, Action<Status.UIStatus> callback)
        {
            Misc.CheckNotNull(callback);

            C.LeaderboardManager_ShowUI(mServices.AsHandle(), leaderboardId,
                (Types.LeaderboardTimeSpan)span,
                Callbacks.InternalShowUICallback, 
                Callbacks.ToIntPtr(callback));
        }
        /// <summary>
        /// Loads the scores using the provided parameters.
        /// </summary>
        /// <param name="leaderboardId">Leaderboard identifier.</param>
        /// <param name="start">Start either top scores, or player centered.</param>
        /// <param name="rowCount">Row count. the number of rows to return.</param>
        /// <param name="collection">Collection. social or public</param>
        /// <param name="timeSpan">Time span. daily, weekly, all-time</param>
        /// <param name="callback">Callback.</param>
        public void LoadScores(string leaderboardId, LeaderboardStart start,
                               int rowCount, LeaderboardCollection collection,
                               LeaderboardTimeSpan timeSpan,
                               Action <LeaderboardScoreData> callback)
        {
            if (!IsAuthenticated())
            {
                GooglePlayGames.OurUtils.Logger.e("LoadScores can only be called after authentication.");
                callback(new LeaderboardScoreData(leaderboardId,
                                                  ResponseStatus.NotAuthorized));
                return;
            }

            mClient.LoadScores(leaderboardId, start,
                               rowCount, collection, timeSpan, callback);
        }
示例#4
0
 /// <summary>
 /// Loads the score data for the given leaderboard.
 /// </summary>
 /// <param name="leaderboardId">Leaderboard identifier.</param>
 /// <param name="start">Start indicating the top scores or player centric</param>
 /// <param name="rowCount">Row count.</param>
 /// <param name="collection">Collection to display.</param>
 /// <param name="timeSpan">Time span.</param>
 /// <param name="callback">Callback to invoke when complete.</param>
 public void LoadScores(
     string leaderboardId,
     LeaderboardStart start,
     int rowCount,
     LeaderboardCollection collection,
     LeaderboardTimeSpan timeSpan,
     Action <LeaderboardScoreData> callback)
 {
     LogUsage();
     if (callback != null)
     {
         callback(new LeaderboardScoreData(
                      leaderboardId,
                      ResponseStatus.LicenseCheckFailed));
     }
 }
示例#5
0
        ///<summary></summary>
        /// <seealso cref="GooglePlayGames.BasicApi.IPlayGamesClient.ShowLeaderboardUI"/>
        public void ShowLeaderboardUI(string leaderboardId, LeaderboardTimeSpan span, Action <UIStatus> callback)
        {
            if (!IsAuthenticated())
            {
                InvokeCallbackOnGameThread(callback, UIStatus.NotAuthorized);
                return;
            }

            if (leaderboardId == null)
            {
                AndroidHelperFragment.ShowAllLeaderboardsUI(AsOnGameThreadCallback(callback));
            }
            else
            {
                AndroidHelperFragment.ShowLeaderboardUI(leaderboardId, span, AsOnGameThreadCallback(callback));
            }
        }
示例#6
0
    private void FetchCurrentUserScore(string id, LeaderboardTimeSpan timeSpan)
    {
        if (!userSignedIn || leaderboardUserLoadState != LeaderboardLoadState.DoneLoading)
        {
            return;
        }

        leaderboardUserLoadState = LeaderboardLoadState.LoadingValues;
        curUserLeaderboardItem.cachedGo.SetActive(false); // Hide current result while loading.

        curUserLeaderboard       = PlayGamesPlatform.Instance.CreateLeaderboard();
        curUserLeaderboard.id    = id;
        curUserLeaderboard.range = new Range(int.MaxValue, 0); // We are only getting our local value. So this range doesn't matter.
        curUserLeaderboard.SetUserFilter(curUserFilter);
        curUserLeaderboard.timeScope = TimeSpanToTimeScope(timeSpan);
        curUserLeaderboard.LoadScores(OnLoadedCurrentUserScore);
    }
示例#7
0
    public void OnNewLeaderboardTimeFrame()
    {
        LeaderboardTimeSpan newSpan = (LeaderboardTimeSpan)(leaderboardTimeFrame.selectionIndex + 1); // Enum starts at 1.

        if (leaderboardTimeSpanSetting == newSpan)
        {
            return; // No need to refresh if the setting didn't change.
        }
        leaderboardTimeSpanSetting = newSpan;

        if (!userSignedIn || leaderboardIsLoading || leaderboardData == null)
        {
            return;
        }

        ReloadCurrentLeaderboard();
    }
        private void getUserScore(LeaderboardCollection collection, LeaderboardTimeSpan interval)
        {
#if UNITY_ANDROID
            PlayGamesPlatform.Instance.LoadScores(GPGSIds.leaderboard_magnet_balls_pro, LeaderboardStart.PlayerCentered, 1, collection, interval,
                                                  (data) =>
            {
                if (data.Scores.Length > 0)
                {
                    if (UserScoreInited != null)
                    {
                        UserScoreInited(data.PlayerScore, collection, interval);
                    }
                }
            }
                                                  );
#endif
        }
示例#9
0
        ///<summary></summary>
        /// <seealso cref="GooglePlayGames.BasicApi.IPlayGamesClient.LoadScores"/>
        public void LoadScores(string leaderboardId, LeaderboardStart start,
                               int rowCount, LeaderboardCollection collection,
                               LeaderboardTimeSpan timeSpan,
                               Action <LeaderboardScoreData> callback)
        {
            using (var client = getLeaderboardsClient())
            {
                string loadScoresMethod =
                    start == LeaderboardStart.TopScores ? "loadTopScores" : "loadPlayerCenteredScores";
                using (var task = client.Call <AndroidJavaObject>(
                           loadScoresMethod,
                           leaderboardId,
                           AndroidJavaConverter.ToLeaderboardVariantTimeSpan(timeSpan),
                           AndroidJavaConverter.ToLeaderboardVariantCollection(collection),
                           rowCount))
                {
                    AndroidTaskUtils.AddOnSuccessListener <AndroidJavaObject>(
                        task,
                        annotatedData =>
                    {
                        using (var leaderboardScores = annotatedData.Call <AndroidJavaObject>("get"))
                        {
                            InvokeCallbackOnGameThread(callback, CreateLeaderboardScoreData(
                                                           leaderboardId,
                                                           collection,
                                                           timeSpan,
                                                           annotatedData.Call <bool>("isStale")
                                        ? ResponseStatus.SuccessWithStale
                                        : ResponseStatus.Success,
                                                           leaderboardScores));
                            leaderboardScores.Call("release");
                        }
                    });

                    AndroidTaskUtils.AddOnFailureListener(
                        task,
                        exception =>
                    {
                        Debug.Log("LoadScores failed");
                        InvokeCallbackOnGameThread(callback,
                                                   new LeaderboardScoreData(leaderboardId, ResponseStatus.InternalError));
                    });
                }
            }
        }
示例#10
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);
    }
示例#11
0
 public void ShowLeaderboardUI(string leaderboardId, LeaderboardTimeSpan span, Action <UIStatus> cb)
 {
     if (IsAuthenticated())
     {
         Action <CommonErrorStatus.UIStatus> callback = Callbacks.NoopUICallback;
         if (cb != null)
         {
             callback = delegate(CommonErrorStatus.UIStatus result)
             {
                 cb((UIStatus)result);
             };
         }
         callback = AsOnGameThreadCallback(callback);
         if (leaderboardId == null)
         {
             GameServices().LeaderboardManager().ShowAllUI(callback);
         }
         else
         {
             GameServices().LeaderboardManager().ShowUI(leaderboardId, span, callback);
         }
     }
 }
        public static void ShowLeaderboardUI(string leaderboardId, LeaderboardTimeSpan timeSpan, Action <UIStatus> cb)
        {
            using (var helperFragment = new AndroidJavaClass(HelperFragmentClass))
                using (var task = helperFragment.CallStatic <AndroidJavaObject>("showLeaderboardUi",
                                                                                GetActivity(), leaderboardId,
                                                                                AndroidJavaConverter.ToLeaderboardVariantTimeSpan(timeSpan)))
                {
                    AndroidTaskUtils.AddOnSuccessListener <int>(
                        task,
                        uiCode =>
                    {
                        Logger.d("ShowLeaderboardUI result " + uiCode);
                        cb.Invoke((UIStatus)uiCode);
                    });

                    AndroidTaskUtils.AddOnFailureListener(
                        task,
                        exception =>
                    {
                        Logger.e("ShowLeaderboardUI failed with exception");
                        cb.Invoke(UIStatus.InternalError);
                    });
                }
        }
 internal void ShowUI(string leaderboardId, LeaderboardTimeSpan span, Action <CommonErrorStatus.UIStatus> callback)
 {
     Misc.CheckNotNull(callback);
     GooglePlayGames.Native.Cwrapper.LeaderboardManager.LeaderboardManager_ShowUI(mServices.AsHandle(), leaderboardId, (Types.LeaderboardTimeSpan)span, Callbacks.InternalShowUICallback, Callbacks.ToIntPtr(callback));
 }
        /// <summary>
        /// Loads the leaderboard data.  This is the "top level" call
        /// to load leaderboard data.  A token for fetching scores is created
        /// based on the parameters.
        /// </summary>
        /// <param name="leaderboardId">Leaderboard identifier.</param>
        /// <param name="start">Start of scores location</param>
        /// <param name="rowCount">Row count.</param>
        /// <param name="collection">Collection social or public</param>
        /// <param name="timeSpan">Time span of leaderboard</param>
        /// <param name="playerId">Player identifier.</param>
        /// <param name="callback">Callback.</param>
        public void LoadLeaderboardData(string leaderboardId,
            LeaderboardStart start,
            int rowCount,
            LeaderboardCollection collection,
            LeaderboardTimeSpan timeSpan,
            string playerId, Action<LeaderboardScoreData> callback)
        {

            //Create a token we'll use to load scores later.
            NativeScorePageToken nativeToken = new NativeScorePageToken(
                                             C.LeaderboardManager_ScorePageToken(
                                                 mServices.AsHandle(),
                                                 leaderboardId,
                                                 (Types.LeaderboardStart)start,
                                                 (Types.LeaderboardTimeSpan)timeSpan,
                                                 (Types.LeaderboardCollection)collection));
            ScorePageToken token = new ScorePageToken(nativeToken, leaderboardId,
                                       collection, timeSpan);

           // First fetch the leaderboard to get the title
            C.LeaderboardManager_Fetch(mServices.AsHandle(),
                Types.DataSource.CACHE_OR_NETWORK,
                leaderboardId,
                InternalFetchCallback,
                Callbacks.ToIntPtr<FetchResponse>((rsp) =>
                    HandleFetch(token, rsp, playerId, rowCount, callback),
                    FetchResponse.FromPointer));

        }
示例#15
0
    private void FetchLeaderboardFromTop(string id, LeaderboardCollection collection, LeaderboardTimeSpan timeSpan)
    {
        if (!userSignedIn)
        {
            return;
        }

        leaderboardListLoadState = LeaderboardLoadState.LoadingValues;
        leaderboardCurPage       = 1;
        leaderboardPageCount     = 1;
        SetLeaderboardListLoading(true);
        PlayGamesPlatform.Instance.LoadScores(id, LeaderboardStart.TopScores, LEADERBOARD_ENTRIES_PER_PAGE, collection, timeSpan, OnLoadedTopLeaderboards);
    }
示例#16
0
 public void LoadScores(string leaderboardId, LeaderboardStart start, int rowCount, LeaderboardCollection collection, LeaderboardTimeSpan timeSpan, Action <LeaderboardScoreData> callback)
 {
     callback = AsOnGameThreadCallback(callback);
     GameServices().LeaderboardManager().LoadLeaderboardData(leaderboardId, start, rowCount, collection, timeSpan, mUser.id, callback);
 }
        /// <summary>
        /// Shows the leaderboard UI and calls the specified callback upon
        /// completion.
        /// </summary>
        /// <param name="lbId">leaderboard ID, can be null meaning all leaderboards.</param>
        /// <param name="span">Timespan to display scores in the leaderboard.</param>
        /// <param name="callback">Callback to call.  If null, nothing is called.</param>
        public void ShowLeaderboardUI(string lbId, LeaderboardTimeSpan span,
            Action<UIStatus> callback)
        {
            if (!IsAuthenticated())
            {
                GooglePlayGames.OurUtils.Logger.e("ShowLeaderboardUI can only be called after authentication.");
                callback(UIStatus.NotAuthorized);
                return;
            }

            GooglePlayGames.OurUtils.Logger.d("ShowLeaderboardUI, lbId=" + lbId + " callback is " + callback);
            mClient.ShowLeaderboardUI(lbId, span, callback);
        }
 public void ShowLeaderboardUI(string leaderboardId, LeaderboardTimeSpan span, System.Action <UIStatus> callback)
 {
     throw new System.NotImplementedException();
 }
 public void LoadScores(string leaderboardId, LeaderboardStart start, int rowCount, LeaderboardCollection collection, LeaderboardTimeSpan timeSpan, System.Action <LeaderboardScoreData> callback)
 {
     throw new System.NotImplementedException();
 }
 public static void GetUserScore(LeaderboardCollection collection, LeaderboardTimeSpan interval)
 {
     main.getUserScore(collection, interval);
 }
        public void LoadLeaderboardData(string leaderboardId, LeaderboardStart start, int rowCount, LeaderboardCollection collection, LeaderboardTimeSpan timeSpan, string playerId, Action <LeaderboardScoreData> callback)
        {
            NativeScorePageToken internalObject = new NativeScorePageToken(GooglePlayGames.Native.Cwrapper.LeaderboardManager.LeaderboardManager_ScorePageToken(mServices.AsHandle(), leaderboardId, (Types.LeaderboardStart)start, (Types.LeaderboardTimeSpan)timeSpan, (Types.LeaderboardCollection)collection));
            ScorePageToken       token          = new ScorePageToken(internalObject, leaderboardId, collection, timeSpan);

            GooglePlayGames.Native.Cwrapper.LeaderboardManager.LeaderboardManager_Fetch(mServices.AsHandle(), Types.DataSource.CACHE_OR_NETWORK, leaderboardId, InternalFetchCallback, Callbacks.ToIntPtr(delegate(FetchResponse rsp)
            {
                HandleFetch(token, rsp, playerId, rowCount, callback);
            }, FetchResponse.FromPointer));
        }
示例#22
0
        private LeaderboardScoreData CreateLeaderboardScoreData(
            string leaderboardId,
            LeaderboardCollection collection,
            LeaderboardTimeSpan timespan,
            ResponseStatus status,
            AndroidJavaObject leaderboardScoresJava)
        {
            LeaderboardScoreData leaderboardScoreData = new LeaderboardScoreData(leaderboardId, status);

            using (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.NextPageToken = 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");
                            string          scoreHolderId = "me";
                            ulong           score         = (ulong)variant.Call <long>("getRawPlayerScore");
                            string          metadata      = variant.Call <string>("getPlayerScoreTag");
                            leaderboardScoreData.PlayerScore = new PlayGamesScore(date, leaderboardId,
                                                                                  rank, scoreHolderId, score, metadata);
                        }

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

            return(leaderboardScoreData);
        }
示例#23
0
 internal ScorePageToken(object internalObject, string id, LeaderboardCollection collection, LeaderboardTimeSpan timespan)
 {
     this.mInternalObject = internalObject;
     this.mId             = id;
     this.mCollection     = collection;
     this.mTimespan       = timespan;
 }
示例#24
0
 public void ShowLeaderboardUI(string leaderboardId, LeaderboardTimeSpan span, Action <UIStatus> callback)
 {
     LogUsage();
     callback?.Invoke(UIStatus.VersionUpdateRequired);
 }
示例#25
0
 /// <summary>
 /// Shows the leaderboard UI
 /// </summary>
 /// <param name="leaderboardId">Leaderboard identifier.</param>
 /// <param name="span">Timespan to display.</param>
 /// <param name="callback">Callback to invoke when complete.</param>
 public void ShowLeaderboardUI(
     string leaderboardId,
     LeaderboardTimeSpan span,
     Action<UIStatus> callback)
 {
     LogUsage();
     if (callback != null)
     {
         callback.Invoke(UIStatus.VersionUpdateRequired);
     }
 }
        /// <summary>
        /// Loads the scores using the provided parameters.
        /// </summary>
        /// <param name="leaderboardId">Leaderboard identifier.</param>
        /// <param name="start">Start either top scores, or player centered.</param>
        /// <param name="rowCount">Row count. the number of rows to return.</param>
        /// <param name="collection">Collection. social or public</param>
        /// <param name="timeSpan">Time span. daily, weekly, all-time</param>
        /// <param name="callback">Callback.</param>
        public void LoadScores(string leaderboardId, LeaderboardStart start,
            int rowCount, LeaderboardCollection collection,
            LeaderboardTimeSpan timeSpan,
            Action<LeaderboardScoreData> callback)
        {
            if (!IsAuthenticated())
            {
                GooglePlayGames.OurUtils.Logger.e("LoadScores can only be called after authentication.");
                callback(new LeaderboardScoreData(leaderboardId,
                    ResponseStatus.NotAuthorized));
                return;
            }

            mClient.LoadScores(leaderboardId, start,
                rowCount, collection, timeSpan, callback);
        }
示例#27
0
 /// <summary>
 /// Loads the score data for the given leaderboard.
 /// </summary>
 /// <param name="leaderboardId">Leaderboard identifier.</param>
 /// <param name="start">Start indicating the top scores or player centric</param>
 /// <param name="rowCount">Row count.</param>
 /// <param name="collection">Collection to display.</param>
 /// <param name="timeSpan">Time span.</param>
 /// <param name="callback">Callback to invoke when complete.</param>
 public void LoadScores(
     string leaderboardId,
     LeaderboardStart start,
     int rowCount,
     LeaderboardCollection collection,
     LeaderboardTimeSpan timeSpan,
     Action<LeaderboardScoreData> callback)
 {
     LogUsage();
     if (callback != null)
     {
         callback(new LeaderboardScoreData(
                 leaderboardId,
                 ResponseStatus.LicenseCheckFailed));
     }
 }
示例#28
0
        private void Main_UserScoreInited(IScore score, LeaderboardCollection collection, LeaderboardTimeSpan interval)
        {
            int best = (int)score.value;

            switch (interval)
            {
            case LeaderboardTimeSpan.Daily:
                PlayGameServiceManager.GetUserScore(LeaderboardCollection.Public, LeaderboardTimeSpan.Weekly);
                GameData.DailyBest = best;
                GameData.DailyRank = score.rank;
                if (DailyScoreInited != null)
                {
                    DailyScoreInited(score);
                }
                break;

            case LeaderboardTimeSpan.Weekly:
                PlayGameServiceManager.GetUserScore(LeaderboardCollection.Public, LeaderboardTimeSpan.AllTime);
                GameData.WeeklyBest = best;
                GameData.WeeklyRank = score.rank;
                if (WeeklyScoreInited != null)
                {
                    WeeklyScoreInited(score);
                }
                break;

            case LeaderboardTimeSpan.AllTime:
                GameData.OverallBest = best;
                GameData.OverallRank = score.rank;
                if (OverallScoreInited != null)
                {
                    OverallScoreInited(score);
                }
                break;
            }
        }
 public virtual void ShowLeaderboardUI(string leaderboardId,
                                       LeaderboardTimeSpan span,
                                       Action <UIStatus> callback)
 {
     throw new NotSupportedException("unsupported");
 }