Google Play登录Unity

时间:2017-11-14 11:37:53

标签: android unity3d google-play-games

我正在尝试整合Google Play服务,以便我可以在游戏中获得成就和排行榜。我尝试过以下代码 -

public Text myText;

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

public void SignIN()
{
    Social.localUser.Authenticate((bool Success) => 
    {
        if (Success)
        {
            myText.text = "Yayy!!";
        }
        else
        {
            myText.text = "Not AGAIN!!";
        }
    });
}

public void SignOUT()
{
    PlayGamesPlatform.Instance.SignOut();
    if (Social.localUser.authenticated == false)
    {
        myText.text = "SIGNED OUT!!";
    }
}

其中SignIN()和SignOUT()在按钮中调用登录并注销但我无法登录。我将来自Google Play开发者控制台的粘贴资源复制到Unity(窗口 - Google Play服务 - 设置 - Android )并在开发者控制台上将我的apk与GooglePlayServices相关联。但是没有用,我无法登录,请帮忙。

4 个答案:

答案 0 :(得分:2)

您可以在本地的团结游戏中测试GPS!

我看到你对这个问题的评论,因为RESOLVED说必须上传和发布apk以使其正常工作。以一种正确的方式。但是,如果您想在每次测试GPS代码时上传apk,那将是一件非常痛苦的事情。

以下是我在本地测试它而无需上传到Google Play控制台的功能。

GPS插件版本0.9.50

  • 请务必按照github of GPS plugin
  • 上的说明操作
  • 在安装插件之前在系统上正确设置JAVA路径
  • 确保您使用Unity(Keystore,Key)跟踪应用程序签名过程
  • 为您的游戏和关联应用等设置Google Play控制台
  • 上传您的apk进行内部测试或alpha / beta测试

现在,在您的应用程序下 - >发布管理 - >应用程序签名后,Google会用自己的应用程序签名证书替换您的上传证书(使用Unity设置的密钥)。这就是我们在设备上直接运行apk时遇到问题的地方。

在击中" Build&运行"在发布设置上启用密钥库和密钥选项的统一下,您的apk将直接构建并通过统一复制到您的手机。现在,在运行游戏时,GPS插件将尝试访问Google Play服务,但由于SHA1不匹配而失败。你的本地apk有SHA1的上传证书,而GPS则需要更新的SHA1证书(谷歌的证书)。

出于测试目的,将上传证书的SHA-1证书指纹从Google Play Console复制到您的Google Developer Console(找到您的应用并点击右侧的编辑按钮)

Google Play控制台 Google Play Console

Google Developer Console enter image description here

在统一构建设置上,确保使用正确的密码选择密钥库和密钥,然后点击"构建并运行"。请注意,如果您的手机上已安装了Play商店版或未安装的版本,请先将其卸载。

enter image description here

现在,每次更新代码时,您都不需要在Google Play控制台上传和发布以测试GPS插件。使用本地上传证书,您可以直接在手机上进行测试,就像正常测试一样。

重要提示:经过测试,您需要将SHA1还原为Google的一个,以使您的GPS能够处理已发布的版本(Playstore版本)。在Google Developer Console下保留上传密钥SHA1之前,Playstore版本的游戏将无法访问GPS。

GPS服务代码(我也启用了云服务),

void InitGooglePlatform()
{
    PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder().EnableSavedGames().Build();
    PlayGamesPlatform.InitializeInstance(config);
    PlayGamesPlatform.DebugLogEnabled = true;
    PlayGamesPlatform.Activate();
    if(!bGoogleCheck)       // internal flag to do this only once if user is offline
        GoogleSignin();
    bGoogleCheck = true;    // Mark it done until the game is restarted again
}
public void GoogleSignin()
{
    if (!Social.localUser.authenticated)
    {
        Social.localUser.Authenticate(success => {
            if(success)
            {
                OpenSave(false);
            }
        });
    }
}

答案 1 :(得分:0)

也许你错过了configuration steps?此代码来自链接,无论如何,它假设您还配置了设置。

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>)
    // requests the email address of the player be available.
    // Will bring up a prompt for consent.
    .RequestEmail()
    // requests a server auth code be generated so it can be passed to an
    //  associated back end server application and exchanged for an OAuth token.
    .RequestServerAuthCode(false)
    // requests an ID token be generated.  This OAuth token can be used to
    //  identify the player to other services such as Firebase.
    .RequestIdToken()
    .Build();

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

答案 2 :(得分:0)

非常感谢,自从我不得不将我的aab上传到Google Play控制台并等待Google验证以来,您就彻底为我节省了几周。

顺便说一句,这个问题花了我很多时间,而且我在互联网上没有看到任何解释。

有时您会收到以下消息: 警告:playgamesplatform已经初始化。忽略此呼叫。

这将阻止您使用平台的保存功能。 实际上,这是由于您可能在调用之前先调用playgamesplatform.instance
    PlayGamesPlatform.InitializeInstance(config);

例如,执行:

if (PlayGamesPlatform.Instance.localUser.authenticated == true)
{
...
}

将强制平台进行实例化。因此,当您真正尝试实例化时,它会告诉您它已经完成了

答案 3 :(得分:-1)

我也有同样的问题:), 尝试使用最新版本的GPG 9.42(2017年11月19日), 尝试取消其他插件,如Admob,Facebook或onesignal,然后重新整合, 问题来自你的插件而不是你的代码:)。

确保您在Google Play Play中添加了测试电子邮件,并创建了3个链接应用程序,2个带有SHA1(已签名和上传)的Android应用程序和1个Web链接应用程序(将您的Google Play链接放入链接空间)和一切都应该工作:)。

祝你好运