我使用 Google Play 游戏服务 Unity 插件构建 Android 游戏,如下所述: https://github.com/playgameservices/play-games-plugin-for-unity
问题:
当我使用 API(Google Play 插件的社交 API 或 PlayGamesPlatform.Instance 对象)加载分数时,我得到过时分数。但是,当我改用 ShowLeaderBoardUI() 函数时,GUI 中的分数是正确的。
因此发布分数没有问题。
我使用以下代码 fragment 从 Google Play 游戏服务记分牌加载用户分数:
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分。请帮忙,我可能哪里错了?
最佳答案
我通过更改 LeaderboardManager.LoadLeaderboardData() 解决了这个问题使用 Types.DataSource.NETWORK_ONLY 与 CACHE_OR_NETWORK。
关于android - Unity Google Play Services Plugin API 与 Show Leaderboard UI 功能不同步?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40828345/