【问题标题】:How to get the current player's leaderboard score in Xamarin如何在 Xamarin 中获取当前玩家的排行榜分数
【发布时间】:2017-01-16 01:39:44
【问题描述】:

我需要增加当前玩家的排行榜分数。为了在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);
    }
}

【问题讨论】:

    标签: android xamarin xamarin.android google-play-services google-play-games


    【解决方案1】:

    使用LoadCurrentPlayerLeaderboardScoreAsync 返回一个ILeaderboardsLoadPlayerScoreResultLoadCurrentPlayerLeaderboardScore,后者返回一个您需要等待和转换的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);
    

    【讨论】:

    • 我不明白。 IPlayersLoadPlayersResult 似乎没有定义 Score() 方法或 Score 属性。它只有一个“PlayerBuffer”对象,看起来只是 java.lang.Object 的列表
    • 你的意思是 ILeaderboardLoadPlayerScoreResult 吗?
    • 使用返回ILeaderboardsLoadPlayerScoreResultLoadCurrentPlayerLeaderboardScoreAsync
    • @b15 我希望!大声笑....我在第一次学习(和猜测)类/接口/枚举在 C# 重命名约定中被“移动”到的位置时使用了source a lot当从 Java 迁移到 C# 时,convention 会与 Google API/包混淆,并且 Java 类名的 C# 变体已重命名(WHY、WHY、WHY、、、、lmao、这样做有真正的原因)...所以我进行这样的搜索:github.com/xamarin/GooglePlayServicesComponents/search?utf8=✓&q=ILeaderboardsLoadPlayerScoreResult 和grep 使用通配符*LoadPlayerScore* 的本地回购克隆。
    • @b15 使用 Android 绑定 Transforms 也是查找 Java 到 C# 重命名的好方法,即:github.com/xamarin/GooglePlayServicesComponents/tree/master/…
    猜你喜欢
    • 2014-06-08
    • 1970-01-01
    • 2012-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-23
    • 2013-08-09
    相关资源
    最近更新 更多