将Google登录接入(play-games-plugin-for-unity)改写为更流畅的表达方式:

Google后台配置

进入google后台:https://play.google.com/apps/publish/?hl=zh&account=5458629459868388661#GameListPlace

新版插件下载:https://github.com/playgameservices/play-games-plugin-for-unity(untiy2018/2017)

旧版插件下载:https://pan.baidu.com/s/14N2ftAiv7EVIbVZjcSJ1fA    密码:d6b3  (unity2017以下)

在接入过程中遇到的困难和问题,请参考以下链接:https://blog.csdn.net/m348915654/article/details/79182221

支持二次验证,后台返回的参数,直接发给服务器验证,服务器要接Google源生的;

 

注:测试机需要Google服务 ,Google play游戏,Google商店;

注:另外上传google后台的证书是由签名做成的,证书需要cmd命令然后生成证书,生成方法百度;

 

 

注:如果apk上传不上去Google后台,请一定要在项目里面的androidmainfest文件里面添加  <uses-permission android:name=”com.android.vending.BILLING” />  就可以了(放到application外面);

注:如果apk上传到google之后,有隐私权政策的错误,需要在隐私权政策上加一个网址,任意一个网址就可以

注:第一次上传google后台的 apk里的签名必须和你的签名证书一致,

注:error: No resource identifier found for attribute ‘enableVrMode’ in package ‘android’  只需要把Androidmanifest.xml文件里的android:targetSdkVersion(API级别)属性设置为24;

注:如果在打包的时候遇到 Failed to compile resources with the following parameters:-bootclasspath “C:/android_tools/android-sdk/sdk\platforms\android-24\android.jar” -d “C:\pubg\trunk\client\Temp\StagingArea\bin\classes” -source 1.6 -target 1.6 -encoding UTF-……………………等等  是JDK的问题版本的问题,换成JDK1.8版本

 

 

 

 

 

如果有不懂的可以加QQ群:636926481

 

(google登录插件版本0.9.39a,支持2017以下版本)

1.点击创建应用

填写项目名称

配置红色指针选项,直到选项出现绿色对号

在Alpha版中点击管理>修改版本>退出计划, 然后就可以上传apk了,上传到开放渠道

注意:如果apk上传到google之后,有隐私权政策的错误,需要在隐私权政策上加一个网址,任意一个网址就可以

填写调查问卷

注意:隐私权政策任意填一个网址

带*号必填

四个选项填完之后返回>点击游戏服务

注意:添加新游戏之后无法删除

选择尚未使用Googel API    然后填写游戏名称

 

带*号必填

添加测试人员(Googel账号)

Google APIS:https://console.developers.google.com/apis/dashboard?project=chaosmech-66580513&duration=PT12H

新建项目,最好和Google后台的项目名称一样

点击启用API和服务>搜索 Google Play Game Services

点击启用API库

点击凭据

切换页面返回Google后台>游戏服务>然后点击发布

再切换页面返回到Google APIS

请点击以下链接下载Google插件:[https://github.com/playgameservices/play-games-plugin-for-unity](https://github.com/playgameservices/play-games-plugin-for-unity)

2、导入GooglePlayGamesPlugin-0.9.36.unitypackage

全选导入,如下图:

3、切换到Android平台

Unity工程File->Build Settings 
选择Android 点击下面的Switch Platform

4、设置Android setup

打开Android setup 

填写页面内容 

 

 

<?xml version=”1.0″ encoding=”utf-8″?>

<!–

Google Play game services IDs.

Save this file as resalues/games-ids.xml in your project.

–>

<resources>

  <!– app_id –>

  <string name=”app_id” translatable=”false”>************</string>

<!– package_name –> 可以被视为一个包的名称。

  <string name=”package_name” translatable=”false”>***************</string>

</resources>

第一个星号串填客户端ID前面的数字串

第二个星号串填项目的包名

Resources Definition 
Google Play后台:在成就或者排行下面有个“获取资源”点击复制拷贝到这边就可以了。

Client ID 
Google Play后台:在关联的应用->选择自己的应用->拉到最下面会看到“OAuth2 客户端 ID”  注:客户端ID为网页客户端
 

客户端代码:login方法放到登录界面的start方法里

public void Login()
{
try
{
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
.RequestIdToken()
.Build();
PlayGamesPlatform.InitializeInstance(config);
// View Google service output information recommended for debugging:
PlayGamesPlatform.DebugLogEnabled = true;
// Activate the Google Play Games platform
// 激活谷歌服务
PlayGamesPlatform.Activate();
if (!PlayGamesPlatform.Instance.localUser.authenticated)
{
// Authenticate user, check if user is logged in:
Social.localUser.Authenticate((bool success) =>
{
if (success)
{
Debug.Log(User authenticated successfully.);
}
else
{
Debug.Log(Failed to authenticate user.);
}
});
}
}
catch (Exception e)
{
Debug.LogError(An error occurred during login:  + e.Message);
}
}

发表评论

您的邮箱地址不会被公开。 必填项已用 * 标注