在输入这个问题之前,我搜索了很多(在这个问题上被困了两个星期:'( )我只瞄准了我的联合项目中的google领导板功能。我遵循以下步骤:
1-整合谷歌玩游戏插件,如:https://github.com/playgameservices/play-games-plugin-for-unity中所述
我使用的密钥存储库与生成SHA1代码的密钥库相同。我在播放器设置和密码中输入了它。
我的包名在所有平台上都是一致的(在google控制台中,在google控制台中,在任何地方都是统一的)
我将测试用户输入到控制台中的测试用户。
2-我在我的闪屏场景中的一个脚本中输入了用于身份验证的代码:
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函数将用户的高分发布到主板上。
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");
}
});
}我简化了代码(不包括不相关的部分)
我得到以下输出
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结论:
W/Unity (15970):游戏插件DLL 07/17/16 18:47:10 +03:00警告:从fetchScoreSummary: GooglePlayGames.Native.PInvoke.FetchScor eSummaryResponse返回的错误
我找不到任何设置的记分板在控制台,让用户访问此记分板等。
救命啊!!我被困在这里两个星期(但有改善,我未能在3天前签约)
发布于 2016-07-18 08:29:56
要显示领导板,您需要调用startActivityForResult并传入创建默认领导板UI的意图。在下面的代码段中,REQUEST_LEADERBOARD是请求代码的任意整数。
startActivityForResult(Games.Leaderboards.getLeaderboardIntent(mGoogleApiClient,
LEADERBOARD_ID), REQUEST_LEADERBOARD);获得球员得分的:
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时,所有应用程序都遵循一个基本模式。在高层次上,您可以遵循以下四个步骤:
https://stackoverflow.com/questions/38423459
复制相似问题