I use Google Play Games Services Unity Plugin to build an Android game as described in: https://github.com/playgameservices/play-games-plugin-for-unity
The problem:
When I load scores using the API (Social API or PlayGamesPlatform.Instance object of the google play plugin), I get out of date scores. But, when I use ShowLeaderBoardUI() function instead, the scores are correct in the GUI.
So there is no problem in posting the scores.
I use the following snippet to load user scores from the Google Play Game Services ScoreBoard:
void LoadUsersAndDisplay(int leaderBoardID,ILeaderboard lb,LeaderBoardEntry[] resultingEntries)
{
// get the user ids
List<string> userIds = new List<string>();
foreach(IScore score in lb.scores) {
userIds.Add(score.userID);
}
// load the profiles and display (or in this case, log)
PlayGamesPlatform.Instance.LoadUsers(userIds.ToArray(), (users) =>
{
string status = "Leaderboard loading: " + lb.title + " count = " +
lb.scores.Length;
int currentUserIndex = 0;
foreach(IScore score in lb.scores) {
IUserProfile user = users[currentUserIndex];
status += "\n" + score.formattedValue + " by " +
(string)(
(user != null) ? user.userName : "**unk_" + score.userID + "**");
resultingEntries[currentUserIndex] = new LeaderBoardEntry(score.rank,user.userName,score.value);
currentUserIndex++;
}
// Get the local user score
LeaderBoardEntry localUserEntry = new LeaderBoardEntry(lb.localUserScore.rank, Social.localUser.userName,lb.localUserScore.value);
// Notify the observers about the receiving of the scores
foreach (LeaderBoardObserver currentObserver in observers) {
Debug.Log ("Notifying the leaderboard observer");
currentObserver.OnScoresReceived (leaderBoardID,resultingEntries,localUserEntry);
}
Debug.Log(status);
});
}
public void getScores(int lbID){
ILeaderboard lb = PlayGamesPlatform.Instance.CreateLeaderboard();
lb.id = leaderboards [lbID].lbOfficialID;
lb.timeScope = TimeScope.AllTime;
lb.userScope = UserScope.Global;
LeaderBoardEntry[] resultingEntries = null;
lb.LoadScores(ok =>
{
if (ok) {
resultingEntries = new LeaderBoardEntry[lb.scores.Length];
LoadUsersAndDisplay(lbID,lb,resultingEntries);
}
else {
Debug.Log("Error retrieving leaderboardi");
}
});
Debug.Log ("Have " + observers.Count + " lbObservers");
}
I have the following output when I print the received leaderboard:
>>Leaderboard loading: Quick Reaction Mode World Ranking count = 1
>>I/Unity (16088): 45 by firatercis
But when I display all times scores for global users, I have the following screenshot:
First, the scoreboard was empty, I scored 45 points. I saw the 45 point in both sides there was no problem. Then I scored 50. But the result I achieved by the API never never updates.
I deleted and re-installed the game, nope. I cleaned the cache of the application, and there shouldn't be any copy of the number 45 anywhere, but I constantly get 45 points by using the API. Please help, where may I be wrong?