首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >统一Android游戏可以使用Google游戏插件登录,但无法从主板加载分数。

统一Android游戏可以使用Google游戏插件登录,但无法从主板加载分数。
EN

Stack Overflow用户
提问于 2016-07-17 16:33:43
回答 1查看 982关注 0票数 0

在输入这个问题之前,我搜索了很多(在这个问题上被困了两个星期:'( )我只瞄准了我的联合项目中的google领导板功能。我遵循以下步骤:

1-整合谷歌玩游戏插件,如:https://github.com/playgameservices/play-games-plugin-for-unity中所述

  • 在我的google控制台中创建了一个google服务游戏条目,并将其链接到我的应用程序(在同一个控制台中),并使用id com.o6systems.zray包进行了开放式alpha测试。
  • 我创建了信用度,并将密钥库/密钥对的SHA1插入到google控制台。
  • 我创造了成就,1个记分板,并将我的资源输入到窗口/ GooglePlayGames/Setup / Android安装程序

我使用的密钥存储库与生成SHA1代码的密钥库相同。我在播放器设置和密码中输入了它。

我的包名在所有平台上都是一致的(在google控制台中,在google控制台中,在任何地方都是统一的)

我将测试用户输入到控制台中的测试用户。

2-我在我的闪屏场景中的一个脚本中输入了用于身份验证的代码:

代码语言:javascript
复制
void Start () {
        #if UNITY_ANDROID
        ConfigureGooglePlay ();
        SignIn ();
        #endif
}

void ConfigureGooglePlay(){

            PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
                .Build();
            PlayGamesPlatform.InitializeInstance(config);
        PlayGamesPlatform.DebugLogEnabled = true;
        PlayGamesPlatform.Activate();
}

void SignIn () {
        Social.localUser.Authenticate (success => {
            if (success) {
                Debug.Log ("Authentication successful");
                string userInfo = "Username: " + Social.localUser.userName +
                                  "\nUser ID: " + Social.localUser.id +
                                  "\nIsUnderage: " + Social.localUser.underage;
                Debug.Log (userInfo);

            //  DisplayGPScore();
            } else
                Debug.Log ("Authentication failed");
        });
    }

在游戏场景中,在游戏结束时,我使用ReportScore函数将用户的高分发布到主板上。

代码语言:javascript
复制
private void OnGameOver(){
        ...
        PostScore(_gm.highScore);
        ..

        DisplayGPScore ();
    }

    internal void LoadUsersAndDisplay(ILeaderboard lb)
    {
        // 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)
        Social.LoadUsers(userIds.ToArray(), (users) =>
            {
                string status = "Leaderboard loading: " + lb.title + " count = " +
                    lb.scores.Length;
                foreach(IScore score in lb.scores) {
                    Debug.Log("" + score.rank + ":" + score.userID); 

                }
                Debug.Log(status);
            });
    }

public void DisplayGPScore(){

        ILeaderboard lb = PlayGamesPlatform.Instance.CreateLeaderboard();
        lb.id = ZRayGameManager.WORLD_LEADERBOARD_ID;
        lb.LoadScores(ok =>
            {
                if (ok) {
                    LoadUsersAndDisplay(lb);
                }
                else {
                    Debug.Log("Error retrieving leaderboardi");
                }
            });
    }

public void PostScore(int score){
        PlayGamesPlatform.Instance.ReportScore(score, ZRayGameManager.WORLD_LEADERBOARD_ID, (bool success) => {

            if(success){
                Debug.Log("High score " + score + " posted");
            }else{
                Debug.Log("High score " + score + " could not be posted");

            }

        });

    }

我简化了代码(不包括不相关的部分)

我得到以下输出

代码语言:javascript
复制
I/Unity   (15970):
I/Unity   (15970): Authentication successful
I/Unity   (15970):
I/Unity   (15970): (Filename: ./artifacts/generated/common/runtime/UnityEngineDe
bugBindings.gen.cpp Line: 37)
I/Unity   (15970):
I/Unity   (15970): Username: RighthandedTuba240
I/Unity   (15970): User ID: g02637898988054749692
I/Unity   (15970): IsUnderage: True
I/Unity   (15970):
I/Unity   (15970): (Filename: ./artifacts/generated/common/runtime/UnityEngineDe
bugBindings.gen.cpp Line: 37)
I/Unity   (15970):
I/Unity   (15970):  [Play Games Plugin DLL] 07/17/16 18:46:52 +03:00 DEBUG: Repo
rtScore: score=100, board=CgkIppHPm-wIEAIQCQ
I/Unity   (15970):
I/Unity   (15970): (Filename: ./artifacts/generated/common/runtime/UnityEngineDe
bugBindings.gen.cpp Line: 37)
I/Unity   (15970):
I/Unity   (15970):  [Play Games Plugin DLL] 07/17/16 18:46:52 +03:00 DEBUG: Nati
ve Submitting score: 100 for lb CgkIppHPm-wIEAIQCQ with metadata:
I/Unity   (15970):
I/Unity   (15970): (Filename: ./artifacts/generated/common/runtime/UnityEngineDe
bugBindings.gen.cpp Line: 37)
I/Unity   (15970):
I/Unity   (15970): User is authenticated
I/Unity   (15970):
I/Unity   (15970): (Filename: ./artifacts/generated/common/runtime/UnityEngineDe
bugBindings.gen.cpp Line: 37)
I/Unity   (15970):
I/Unity   (15970):  [Play Games Plugin DLL] 07/17/16 18:46:52 +03:00 DEBUG: Load
Scores, board=GooglePlayGames.PlayGamesLeaderboard callback is System.Action`1[S
ystem.Boolean]
I/Unity   (15970):
I/Unity   (15970): (Filename: ./artifacts/generated/common/runtime/UnityEngineDe
bugBindings.gen.cpp Line: 37)
I/Unity   (15970):
I/Unity   (15970):  [Play Games Plugin DLL] 07/17/16 18:46:52 +03:00 DEBUG: Invo
king user callback on game thread
I/Unity   (15970):
I/Unity   (15970): (Filename: ./artifacts/generated/common/runtime/UnityEngineDe
bugBindings.gen.cpp Line: 37)
I/Unity   (15970):
I/Unity   (15970): High score 100 posted
I/Unity   (15970):
I/Unity   (15970): (Filename: ./artifacts/generated/common/runtime/UnityEngineDe
bugBindings.gen.cpp Line: 37)
I/Unity   (15970):
I/Unity   (15970):  [Play Games Plugin DLL] 07/17/16 18:46:55 +03:00 DEBUG: Ente
ring internal callback for LeaderboardManager#InternalFetchCallback
I/Unity   (15970):
I/Unity   (15970): (Filename: ./artifacts/generated/common/runtime/UnityEngineDe
bugBindings.gen.cpp Line: 37)
I/Unity   (15970):
I/Unity   (15970):  [Play Games Plugin DLL] 07/17/16 18:47:10 +03:00 DEBUG: Star
ting Auth Transition. Op: SIGN_OUT status: ERROR_NOT_AUTHORIZED
I/Unity   (15970):
I/Unity   (15970): (Filename: ./artifacts/generated/common/runtime/UnityEngineDe
bugBindings.gen.cpp Line: 37)
I/Unity   (15970):
I/Unity   (15970):  [Play Games Plugin DLL] 07/17/16 18:47:10 +03:00 DEBUG: Ente
ring internal callback for LeaderboardManager#InternalFetchSummaryCallback
I/Unity   (15970):
I/Unity   (15970): (Filename: ./artifacts/generated/common/runtime/UnityEngineDe
bugBindings.gen.cpp Line: 37)
I/Unity   (15970):
W/Unity   (15970): !!! [Play Games Plugin DLL] 07/17/16 18:47:10 +03:00 WARNING:
 Error returned from fetchScoreSummary: GooglePlayGames.Native.PInvoke.FetchScor
eSummaryResponse
W/Unity   (15970):
W/Unity   (15970): (Filename: ./artifacts/generated/common/runtime/UnityEngineDe
bugBindings.gen.cpp Line: 37)
W/Unity   (15970):
I/Unity   (15970):  [Play Games Plugin DLL] 07/17/16 18:47:10 +03:00 DEBUG: Invo
king user callback on game thread
I/Unity   (15970):
I/Unity   (15970): (Filename: ./artifacts/generated/common/runtime/UnityEngineDe
bugBindings.gen.cpp Line: 37)
I/Unity   (15970):
I/Unity   (15970): Error retrieving leaderboardi

结论:

  1. 用户可以进行身份验证,因为方法登录()告诉身份验证成功,并打印出用户信息。
  2. 用户可以将他/她的分数张贴到记分板上,因为PostScore方法告诉“高分100分张贴”
  3. 用户无法显示记分板得分,错误为

W/Unity (15970):游戏插件DLL 07/17/16 18:47:10 +03:00警告:从fetchScoreSummary: GooglePlayGames.Native.PInvoke.FetchScor eSummaryResponse返回的错误

我找不到任何设置的记分板在控制台,让用户访问此记分板等。

救命啊!!我被困在这里两个星期(但有改善,我未能在3天前签约)

EN

回答 1

Stack Overflow用户

发布于 2016-07-18 08:29:56

要显示领导板,您需要调用startActivityForResult并传入创建默认领导板UI的意图。在下面的代码段中,REQUEST_LEADERBOARD是请求代码的任意整数。

代码语言:javascript
复制
startActivityForResult(Games.Leaderboards.getLeaderboardIntent(mGoogleApiClient,
LEADERBOARD_ID), REQUEST_LEADERBOARD);

获得球员得分的

代码语言:javascript
复制
Private void loadScoreOfLeaderBoard() {
Games.Leaderboards.loadCurrentPlayerLeaderboardScore(getApiClient(), getString(R.string.your_leaderboard_id), LeaderboardVariant.TIME_SPAN_ALL_TIME, LeaderboardVariant.COLLECTION_PUBLIC).setResultCallback(new ResultCallback<Leaderboards.LoadPlayerScoreResult>() {
@Override
public void onResult(final Leaderboards.LoadPlayerScoreResult scoreResult) {
if (isScoreResultValid(scoreResult)) {
// here you can get the score like this
mPoints = scoreResult.getScore().getRawScore();
}
}
});
}

private boolean isScoreResultValid(final Leaderboards.LoadPlayerScoreResult scoreResult) {
return scoreResult != null && GamesStatusCodes.STATUS_OK == scoreResult.getStatus().getStatusCode() && scoreResult.getScore() != null;
}

SIGN_OUT status: ERROR_NOT_AUTHORIZED

确保您有正确的SHA1指纹。由于与Google服务的集成,Android上的授权请求不同于其他授权工作流。

当使用Google2.0访问Google时,所有应用程序都遵循一个基本模式。在高层次上,您可以遵循以下四个步骤:

  • 从Google控制台获取OAuth 2.0凭据。
  • 从Google授权服务器获取访问令牌。
  • 将访问令牌发送到API。
  • 如果有必要,刷新访问令牌。
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38423459

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档