Top 5 scores from google leaderboard

前端 未结 4 445
粉色の甜心
粉色の甜心 2020-12-14 13:47

My requirement is to get top 5 scores from leaderboard and display it in my app.

There is a method loadTopScores but it shows the scores in its own UI i guess.

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-14 14:23

    Here is how I have achieved it.

    PendingResult topScores = 
                Games.Leaderboards.loadTopScores(getApiClient(),LEADERBOARD_ID,LeaderboardVariant.TIME_SPAN_ALL_TIME, LeaderboardVariant.COLLECTION_PUBLIC, 1, true);
                topScores.setResultCallback(new ResultCallback() {
    
                    @Override
                    public void onResult(LoadScoresResult scoreResults) {
    
                        if(scoreResults != null) {
                            if (scoreResults.getStatus().getStatusCode() == GamesStatusCodes.STATUS_OK) {
                                scoreStringBuilder = new StringBuilder();
                                LeaderboardScoreBuffer scoreBuffer = scoreResults.getScores();
                                Iterator it = scoreBuffer.iterator();
                                while(it.hasNext()){
                                     LeaderboardScore temp = it.next();
                                     Log.d("PlayGames", "player"+temp.getScoreHolderDisplayName()+" id:"+temp.getRawScore() + " Rank: "+temp.getRank());
                                     scoreStringBuilder.append("|"+temp.getScoreHolderDisplayName()+"*"+temp.getRawScore());
                                }
                                UnityPlayer.UnitySendMessage(handlerName, "onGetScoreSucceededEventListener", "");
                                 Log.d("PlayGames", "Call Sent for getHighScorewithPlayerNameSuccess ::: "+handlerName);
    
    
                            }
                        }
    
                    }});
    

    You can use it as you want I created a String and returned it to Unity and then parsed it. But this code is working with Latest Google Play Services.

    Thanks

提交回复
热议问题