我需要增加当前玩家的排行榜得分。为了在java中执行此操作,我做了类似这样的事情:
PendingResult<Leaderboards.LoadPlayerScoreResult> result = Games.Leaderboards.loadCurrentPlayerLeaderboardScore(mGoogleApiClient, getString(R.string.winsleaderboardid), LeaderboardVariant.TIME_SPAN_ALL_TIME, LeaderboardVariant.COLLECTION_PUBLIC);
if(result != null)
{
result.setResultCallback(new ResultCallback<Leaderboards.LoadPlayerScoreResult>() {
@Override
public void onResult(Leaderboards.LoadPlayerScoreResult loadPlayerScoreResult) {
if(loadPlayerScoreResult != null && loadPlayerScoreResult.getScore() != null)
{
Games.Leaderboards.submitScore(mGoogleApiClient, getString(R.string.winsleaderboardid), loadPlayerScoreResult.getScore().getRawScore() + 1);
}
else
{
Games.Leaderboards.submitScore(mGoogleApiClient, getString(R.string.winsleaderboardid), 1);
}
}
});
}
我似乎无法在Xamarin中找到ILoadPlayerScoreResult的界面,但我期望类似:
private async void IncrementLeaderBoardWins()
{
IResult result = await GamesClass.Leaderboards.LoadCurrentPlayerLeaderboardScore(
mGoogleApiClient, GetString(Resource.String.winsleaderboardid), Android.Gms.Games.LeaderBoard.LeaderboardVariant.TimeSpanAllTime,
Android.Gms.Games.LeaderBoard.LeaderboardVariant.CollectionPublic);
OnResult(result);
}
public void OnResult(ILoadPlayerScoreResult loadPlayerScoreResult)
{
if (loadPlayerScoreResult != null && loadPlayerScoreResult.getScore() != null)
{
GamesClass.Leaderboards.SubmitScore(mGoogleApiClient, GetString(Resource.String.winsleaderboardid), loadPlayerScoreResult.getScore().getRawScore() + 1);
}
else
{
GamesClass.Leaderboards.SubmitScore(mGoogleApiClient, GetString(Resource.String.winsleaderboardid), 1);
}
}
答案 0 :(得分:1)
使用LoadCurrentPlayerLeaderboardScoreAsync
返回ILeaderboardsLoadPlayerScoreResult
与LoadCurrentPlayerLeaderboardScore
,返回您需要等待并投射的IResult
。
var myGamerID = "StackOverflowGamer";
var score = 9999;
var client = new GoogleApiClient.Builder(this).AddApi(GamesClass.API).AddScope(GamesClass.ScopeGames).Build();
client.BlockingConnect();
var result = await GamesClass.Leaderboards.LoadCurrentPlayerLeaderboardScoreAsync(client, "StackOverflowLeaderBoard", LeaderboardVariant.TimeSpanAllTime, LeaderboardVariant.CollectionPublic);
Console.WriteLine(result.Score);
GamesClass.Leaderboards.SubmitScore(client, myGamerID, score);