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

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

问题描述

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

public Text myText;无效唤醒(){PlayGamesPlatform.Activate();}公共无效登录(){Social.localUser.Authenticate((bool Success) =>{如果(成功){myText.text = "Yayy!!";}别的{myText.text = "再也不会了!!";}});}公共无效退出(){PlayGamesPlatform.Instance.SignOut();如果(Social.localUser.authenticated == false){myText.text = "退出!!";}}

在按钮登录和注销中调用 SignIN() 和 SignOUT() 但我无法登录.) 并将我的 apk 与 Developer Console 上的 GooglePlayServices 相关联.但是我无法登录也没有用,请帮忙.

解决方案

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

我看到你对这个问题的评论,因为 RESOLVED 说必须上传和发布 apk 才能使其正常工作.从某种意义上说是正确的.但是,如果您每次想测试 GPS 代码时都想上传 apk,那将是一件痛苦的事情.

这是对我有用的东西,无需上传到 Google Play 控制台即可在本地对其进行测试.

GPS 插件版本 0.9.50

  • 请务必按照

    Google 开发者控制台

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

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

    重要提示:测试后,您需要将 SHA1 恢复为 Google 的 SHA1,以使您的 GPS 在发布版本(Playstore 版本)上工作.除非您将上传密钥 SHA1 保留在 Google Developer Console 下,否则您游戏的 Playstore 版本将无法访问 GPS.

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

    void InitGooglePlatform(){PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder().EnableSavedGames().Build();PlayGamesPlatform.InitializeInstance(config);PlayGamesPlatform.DebugLogEnabled = true;PlayGamesPlatform.Activate();if(!bGoogleCheck)//如果用户离线,内部标志只执行一次谷歌登录();bGoogleCheck = 真;//标记为完成,直到游戏重新开始}公共无效 GoogleSignin(){如果(!Social.localUser.authenticated){Social.localUser.Authenticate(成功=> {如果(成功){打开保存(假);}});}}

    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!!";
        }
    }
    

    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.

    解决方案

    You can test GPS on your unity game locally!!!

    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.

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

    GPS plugin version 0.9.50

    • 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

    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.

    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).

    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 Console

    Google Developer Console

    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.

    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.

    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.

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

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

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