Xamarin中如何获取当前玩家的排行榜分数
How to get the current player's leaderboard score in Xamarin
我需要增加当前玩家的排行榜分数。为了在 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);
}
}
使用 LoadCurrentPlayerLeaderboardScoreAsync
到 return 一个 ILeaderboardsLoadPlayerScoreResult
与 LoadCurrentPlayerLeaderboardScore
那个 return 一个 IResult
你需要等待和投射.
快速示例:
var myGamerID = "WhosebugGamer";
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, "WhosebugLeaderBoard", LeaderboardVariant.TimeSpanAllTime, LeaderboardVariant.CollectionPublic);
Console.WriteLine(result.Score);
GamesClass.Leaderboards.SubmitScore(client, myGamerID, score);
我需要增加当前玩家的排行榜分数。为了在 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);
}
}
使用 LoadCurrentPlayerLeaderboardScoreAsync
到 return 一个 ILeaderboardsLoadPlayerScoreResult
与 LoadCurrentPlayerLeaderboardScore
那个 return 一个 IResult
你需要等待和投射.
快速示例:
var myGamerID = "WhosebugGamer";
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, "WhosebugLeaderBoard", LeaderboardVariant.TimeSpanAllTime, LeaderboardVariant.CollectionPublic);
Console.WriteLine(result.Score);
GamesClass.Leaderboards.SubmitScore(client, myGamerID, score);