C# Unity GooglePlayGames LoadScores总是一无所获
我正试图用谷歌游戏从一个领头羊的棋盘上获取最高分,但是它没有返回任何东西。有人能给我指出正确的方向吗C# Unity GooglePlayGames LoadScores总是一无所获,c#,unity3d,google-play-services,google-play-games,C#,Unity3d,Google Play Services,Google Play Games,我正试图用谷歌游戏从一个领头羊的棋盘上获取最高分,但是它没有返回任何东西。有人能给我指出正确的方向吗 public int WorldRecord() { int topScore = 0; PlayGamesPlatform.Instance.LoadScores( GPGSIds.leaderboard_quick_fire_scores, LeaderboardStart.TopScores, 1, Leaderboa
public int WorldRecord()
{
int topScore = 0;
PlayGamesPlatform.Instance.LoadScores(
GPGSIds.leaderboard_quick_fire_scores,
LeaderboardStart.TopScores, 1,
LeaderboardCollection.Public,
LeaderboardTimeSpan.AllTime,
(LeaderboardScoreData data) =>
{
topScore = (int)data.Scores[0].value;
});
return topScore;
}
谢谢
PlayGamesPlatform.Instance.LoadScores
运行异步并在完成后执行传递的操作
但是,您的方法不会等到该请求实际完成,因此只返回默认值0
,而不是在LoadScores
实际完成并提供有效结果之前
您可能更愿意使用某种回调,例如
public void WorldRecord(Action<int> onResult)
{
PlayGamesPlatform.Instance.LoadScores(
GPGSIds.leaderboard_quick_fire_scores,
LeaderboardStart.TopScores, 1,
LeaderboardCollection.Public,
LeaderboardTimeSpan.AllTime,
(LeaderboardScoreData data) =>
{
onResult?.Invoke((int)data.Scores[0].value);
});
}
WorldRecord(topScore =>
{
Debug.Log($"Top Score: {topScore}");
});
PlayGamesPlatform.Instance.LoadScores
异步运行,并在完成后执行传递的操作
但是,您的方法不会等到该请求实际完成,因此只返回默认值0
,而不是在LoadScores
实际完成并提供有效结果之前
您可能更愿意使用某种回调,例如
public void WorldRecord(Action<int> onResult)
{
PlayGamesPlatform.Instance.LoadScores(
GPGSIds.leaderboard_quick_fire_scores,
LeaderboardStart.TopScores, 1,
LeaderboardCollection.Public,
LeaderboardTimeSpan.AllTime,
(LeaderboardScoreData data) =>
{
onResult?.Invoke((int)data.Scores[0].value);
});
}
WorldRecord(topScore =>
{
Debug.Log($"Top Score: {topScore}");
});
这就解决了问题。非常感谢,这就解决了。非常感谢你。