Unity接入Google Play 游戏-使用play-games-plugin-for-unity

来源:互联网 发布:期货交易统计软件 编辑:程序博客网 时间:2024/05/22 06:05

Unity接入Google Play 游戏-使用play-games-plugin-for-unity

Git地址:https://github.com/playgameservices/play-games-plugin-for-unity

环境

Unity 5.5.2f1 Personal
Android Studio 2.3
Mac 10.12.4
默认已翻墙

可以先看看视频

接入的视频
https://www.youtube.com/watch?v=BhSJK-Kn8Uw
可以先看下github工程里面的document
https://github.com/playgameservices/play-games-plugin-for-unity

准备

要先创建自己的游戏,设置好成就和排行,发布测试版本等。

步骤

1、(现在已经是0.9.37了)下载GooglePlayGamesPlugin-0.9.36.unitypackage

下载地址在github工程playgameservices/play-games-plugin-for-unity/current-build里
https://github.com/playgameservices/play-games-plugin-for-unity/tree/master/current-build

2、导入GooglePlayGamesPlugin-0.9.36.unitypackage

全选导入,如下图:

这里写图片描述

3、切换到Android平台

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

4、设置Android setup

打开Android setup
这里写图片描述
填写页面内容
这里写图片描述

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

Client ID
Google Play后台:在关联的应用->选择自己的应用->拉到最下面会看到“OAuth2 客户端 ID”
这里写图片描述

5、(可以忽略了,新的版本 0.9.37已经修复了这个问题)去掉Enable Background resolution 的选择状态

选择Assets->Play Services Resolver->Android Resolver->Settings

这里写图片描述

6、(可以忽略了,新的版本 0.9.37已经修复了这个问题)把Plugins->Android的SDK替换为10.0.1的

第4步中的Android setup会自动把play-services-xxxx都变成最新版的,10.2.1但是,10.2.1,程序一运行就crash了,估计以后版本会修复这个,先替换回去就可以使用了。

这里写图片描述

7、其他修改

1)把play-services-basement-10.0.1拷贝一份到
Plugins->Android->MainLibProj->libs里面
2) Plugins->Android->MainLibProj里面的AndroidManifest

<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="25" />

8、导入测试工程

在github上的play-games-plugin-for-unity的有几个例子导入Minimal

https://github.com/playgameservices/play-games-plugin-for-unity/tree/master/samples/Minimal

测试

导出Android工程
在publishing Settings 里面生成一个keystore,设置密码 Alias等

1、设置gradle-wrapper.properties

distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip

2、拷贝 compile(name: ‘play-services-basement-10.0.1’, ext:’aar’)

拷贝 compile(name: ‘play-services-basement-10.0.1’, ext:’aar’)到build.gradle(Module: MainLibProj)里面

这个主要是为了解决:

Error: No resource found that matches the given name (at 'value' with value '@integer/google_play_services_version').

3、在build.gradle(xxx)工程的build.gradle里面

signingConfig signingConfigs.release
在release 和dubug模式都要填写,没有签名,google play games是登陆不了的。

    buildTypes {        debug {            jniDebuggable true            signingConfig signingConfigs.release        }        release {            minifyEnabled false            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'            signingConfig signingConfigs.release        }

文档时间:2017年04月12日
写这个主要是为了记录两个问题
1、上面的测试2

Error: No resource found that matches the given name (at 'value' with value '@integer/google_play_services_version').

2、上面的步骤6 改play-services-xxxx,10.2.1为10.2.1
10.2.1直接就crash了,新版本0.9.37已经修复了这个问题


常见问题

每次登录成功后,会提示选择账号

具体如下图所示:
出现这个的原因是,应用要读取token或mail等信息,就要求用户选择账号。
详细信息查看这个链接

这里写图片描述

iOS平台去除

参考http://blog.csdn.net/cocos2der/article/details/48313653
Google Play Game可以通过设置NO_GPGS才实现不接入Google Play Games
NO_GPGS定义就是用来关闭iOS版的。

#if (UNITY_ANDROID || (UNITY_IPHONE && !NO_GPGS))

定义NO_GPGS,用来关闭其iOS模块:

设置方法:
File->Build Setttings->选择iOS平台->Player Settings->Other Setttings,在Scripting Define Symbol中添加NO_GPGS
这里写图片描述

移除Plugins下的iOS文件夹,里面可能包含
GPGSAppController.h
GPGSAppController.mm

这样就可以了

1 0
原创粉丝点击