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.
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