Google Play登录Unity [英] Google Play Sign in for Unity

查看:646
本文介绍了Google Play登录Unity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试集成Google Play服务,以便在游戏中获得成就和排行榜.我尝试了以下代码-

I am trying to integrate Google play Services so that i can have achievements and leader boards in my game.I have tried the following code -

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链接了.但这无济于事,我无法登录,请帮助.

where SignIN() and SignOUT() are called in buttons Sign IN and Sign OUT but i am unable to Sign in.I have Copy pasted resources from Google play developer console into Unity(Window - Google Play Services - SetUp - Android)and also linked my apk with GooglePlayServices on Developer Console. But it's no use i am unable to sign in, please help.

推荐答案

您可以在本地的统一游戏中测试GPS!

我已看到您对这个问题的评论,因为决议说apk必须上载并发布才能正常工作.以一种正确的方式.但是,如果您想每次测试GPS代码时都上传apk,那将是一件痛苦的事情.

I see your comment on the question as RESOLVED saying apk has to be uploaded and published to get this working. In a way that is correct. But, that will be the painful thing to do if you want to upload apk everytime when you want to test your GPS code.

这是对我有用的东西,可以在本地进行测试而不上传到Google Play控制台.

Here is the thing that worked for me for testing it locally without uploading to Google Play Console.

GPS插件版本0.9.50

GPS plugin version 0.9.50

  • 请务必遵循 GPS插件的github上的说明
  • 在安装插件之前,请在系统上正确设置JAVA路径
  • 确保您使用Unity(密钥库,密钥)遵循了应用程序签名过程
  • 为您的游戏和链接的应用等设置Google Play控制台
  • 上传APK以进行内部测试或alpha/beta测试
  • Make sure to follow the instructions on github of GPS plugin
  • Set the JAVA path correctly on system before installing the plugin
  • Make sure you followed the app signing process with Unity (Keystore, Key)
  • Setup your Google play console for your game and linked app, etc
  • Upload your apk for internal testing or alpha/beta testing

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

Now, under your Application --> Release Management --> App Signing, Google would have replaced your upload certificate (the Key you setup with Unity) with its own App signing certificate. That's where we get the issue while running the apk directly on device.

同时在发布设置"中启用了密钥库"和密钥"选项的情况下,一键打构建并运行",您的apk将被直接构建并直接复制到手机中.现在,在运行游戏时,GPS插件将尝试访问Google Play服务,但由于SHA1不匹配而失败.您本地的apk拥有SHA1的上载证书,GPS希望获得更新的SHA1证书(Google的证书).

While hitting "Build & Run" on unity with Keystore and Key options enabled on Publish settings, your apk will be built and copied to your phone directly by unity. Now while running your game, GPS plugin will try to access Google Play Service, but will fail due to SHA1 mismatch. Your local apk has SHA1 of Upload certificate and GPS is expecting the updated SHA1 certificate (Google's one).

出于测试目的,从 Google Play控制台中复制上传证书的SHA-1证书指纹 到您的 Google开发者控制台 (找到您的应用程序,然后单击右侧的编辑"按钮.

For testing purpose, copy the SHA-1 certificate fingerprint of Upload Certificate from Google Play Console to your Google Developer Console (find your application and click on edit button on right)

Google Play控制台

Google Developer Console

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

On unity build settings, make sure Keystore and Key are selected with correct passwords and hit "Build and Run". Note that, if you already have play store version or unsinged version installed on your phone, uninstall it first.

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

Now, everytime you update your code, you don't need to upload and publish on Google Play Console to test the GPS plugin. With your local upload certificate, you can test it directly on your phone as good as your normal testing.

重要:测试后,您需要将SHA1还原为Google的SHA1,以使GPS在已发布的版本(Playstore版本)上正常工作.在您将上传密钥SHA1保留在Google Developer Console下之前,您的游戏的Playstore版本将无法访问GPS.

Important: After testing, you need to revert the SHA1 back to Google's one to get your GPS working on released versions (Playstore versions). Until you keep the upload key SHA1 under Google Developer Console, Playstore versions of your game will fail to access GPS.

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

Code for GPS service (I have cloud service enabled as well),

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);
            }
        });
    }
}

这篇关于Google Play登录Unity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆