Google Play服务Unity插件未显示排行榜

时间:2015-07-12 20:54:19

标签: android unity3d google-play-services google-play-games

我正在使用Unity 5构建Android游戏,我已导入此plugin

但它没有正常工作我遵循了tutorial

当我尝试发布或显示排行榜时,它没有显示任何内容。它甚至不会抛出任何错误。登录和退出工作正常。请帮助

代码:

public void LogIn ()
{
    Social.localUser.Authenticate ((bool success) =>
    {
        if (success) {
            Debug.Log ("Login Sucess");
        } else {
            Debug.Log ("Login failed");
        }
    });
}

public void LogOut ()
{
    PlayGamesPlatform.Instance.SignOut ();
}

public void Post ()
{

    if (Social.localUser.authenticated) {
        Social.ReportScore (5000, LeaderbordId, (bool success) =>
        {
            if (success) {
                ((PlayGamesPlatform)Social.Active).ShowLeaderboardUI (LeaderbordId);
            } else {
                Debug.Log ("Add Score Fail");
            }
        });
    } 
}

public void ShowLeader ()
{

    Social.ShowLeaderboardUI ();
}

2 个答案:

答案 0 :(得分:1)

我不确定我是否得到你想要的东西。我认为你每次发布分数时都试图打开排行榜。我会更改您的脚本以便更容易理解。

当您使用Google Play服务插件时,您需要了解一些事项。确保你有这个。在脚本的顶部你会写:

using GooglePlayGames;
using UnityEngine.SocialPlatforms;

然后你需要将它添加到你的开始函数中:

void Start(){
    PlayGamesPlatform.Activate();
}

如果您只是为了显示排行榜而设置一个功能,例如上一个功能,那就更容易了:

public void ShowLB(){
    ((PlayGamesPlatform) Social.Active).ShowLeaderboardUI("YOUR_LEADERBOARDS_ID_HERE");
}

然后你的Post()函数会是这样的:

public void Post (){

    if (Social.localUser.authenticated) {
        Social.ReportScore (5000, LeaderbordId, (bool success) =>
        {
            if (success) {
                ShowLB ();
            } else {
                Debug.Log ("Add Score Fail");
            }
        });
    } 
}

似乎在你的上一个函数中你可能想要这样做:

public void ShowAchievs(){
    Social.ShowAchievementsUI ();
}

否则它应该是这样的:

public void ShowLB(){
    ((PlayGamesPlatform) Social.Active).ShowLeaderboardUI("YOUR_LEADERBOARDS_ID_HERE");
}

但如果你只是在触发后使用你的帖子功能,比如游戏结束,并使用别的东西来显示你的LB,那就更方便了。就像点击按钮或其他东西一样。

我不知道那是你想要的。

答案 1 :(得分:0)

您必须在编辑器中运行游戏,您需要在实际设备中运行游戏,或者使用模拟器(使用gmail帐户...罕见)

这是事情...... 打开一个控制台,然后输入

adb logcat 

或者您可以通过仅过滤来自unity的日志来缩小结果

adb logcat -s Unity

打开你的游戏,看看控制台如果你得到

  

ShowAchievementsUI未实施

  

ShowLeaderboardsUI未实现

这仅表示您使用的是默认配置(统一配置) 我建议你用google play

替换默认值
  

默认配置需要替换并使用自定义配置

    using GooglePlayGames;
    using GooglePlayGames.BasicApi;
    using UnityEngine.SocialPlatforms;

    PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
        // enables saving game progress.
        .EnableSavedGames()
        // registers a callback to handle game invitations received while the game is not running.
        .WithInvitationDelegate(<callback method>)
        // registers a callback for turn based match notifications received while the
        // game is not running.
        .WithMatchDelegate(<callback method>)
        .Build();

    PlayGamesPlatform.InitializeInstance(config);
    // recommended for debugging:
    PlayGamesPlatform.DebugLogEnabled = true;
    // Activate the Google Play Games platform
    PlayGamesPlatform.Activate();

现在任何错误都会显示在控制台中,实际上你不需要它的全部工作,你只需要这些

PlayGamesPlatform.DebugLogEnabled = true;
PlayGamesPlatform.Activate();

用于记录错误, 然后你可以验证:)

如果您打开它并突然崩溃,则表示您的清单文件中存在问题

如果您使用旧版本,则可能需要此功能(如果您使用的是最新版本,则会自动添加)

<application ... >
...
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
....
</application>   

确保您通过SDK管理器将 google play服务更新为最新版本,这样可以避免令人不快的情况

干杯。

相关问题