我使用Google Play Games Services Unity插件构建Android游戏,如下所述:https://github.com/playgameservices/play-games-plugin-for-unity
问题:
当我使用API(Social API或google play插件的PlayGamesPlatform.Instance对象)加载分数时,我会得到过时的分数。但是,当我使用ShowLeaderBoardUI()函数时,GUI中的分数是正确的。
因此,在发布分数方面没有问题。
我使用以下代码片段从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");
}
当我打印接收到的排行榜时,输出如下:
>>Leaderboard loading: Quick Reaction Mode World Ranking count = 1
>>I/Unity (16088): 45 by firatercis
但是当我显示全球用户所有时间的得分时,我看到了以下截图:
首先,排行榜是空的,我得了45分。在两侧都看到了45分,没有问题。 然后我得了50分。但是通过 API 实现的结果从未更新。
我已经删除并重新安装了游戏,但还是不行。 我清理了应用程序的缓存,并且不应该有任何关于数字 45 的副本,但是我仍然通过使用 API 得到了 45 分。请帮忙看看,我可能错在哪里了?
Social.ReportScore
进行发布。 - Programmer