Google Play 游戏服务

类型
修订 发行版 2024.3703
关键字 google、google play 游戏服务、成就、排行榜
平台 Android
示例 GitHub

概览

此插件能够访问成就、排行榜和保存游戏(保存进度)等 Google Play 游戏服务 API。

在开始使用此插件之前,请务必查阅 Google 设置指南

如果您在实施此插件后遇到Google Play 游戏服务登录问题/错误,请确保您已启用Google Play 开发者 API具体操作请参见 Google Play 开发者控制台

另外,为了使用 保存游戏,您必须在 Google Play 开发者控制台 中添加 云端硬盘 API

重要

如果您使用 复制到设备 在本地部署应用程序,Google Play 游戏服务不会起作用。您必须使用 Google Play 的测试计划(内部、封闭或公开测试)来部署您的应用程序。

从 GPGS V2 到 V3 的变更

已更改的 API

gpgs.init()

现在需要初始化,它将尝试自动登录玩家

gpgs.isConnected(listener)

isConnected 现在是异步的,而且有一个回调。使用 isConnected 检查玩家是否通过 init 自动连接或通过 login 函数手动连接

gpgs.isAuthenticated()

isAuthenticated 实际上是相同的,但应当注意的是 isAuthenticated 仅适用于通过 gpgs.login() 登录的情况。这对 保存游戏 很重要,后者需要使用 gpgs.login() 请求 云端硬盘 API 访问权限。

gpgs.login()

有一个新的 useDrive 参数,它对 保存游戏 是必要的。务必注意的是,默认情况下不会添加云端硬盘权限范围,您必须将 useDrive 参数设置为 true

不再受支持的功能

gpgs.setPopupPosition()

gpgs.showSettings()

gpgs.loadGame()

gpgs.clearNotifications()

gpgs.videos.*

恢复到 gpgs.v2 以使用这些功能

语法

local gpgs= require( "plugin.gpgs.v3" )

项目设置

要使用此插件,请在 build.settingsplugins 表中添加一个条目。添加后,构建服务器将在构建阶段集成该插件。

settings = {

    plugins =
    {
        ["plugin.gpgs.v3"] =
        {
            publisherId = "com.solar2d",
        },
    },
}

此外,您还必须指定Google Play 游戏应用程序 ID具体操作请参见 build.settingsandroid 表,将其作为 googlePlayGamesAppId

settings = {

    android =
    {
        googlePlayGamesAppId = "YOUR_APPLICATION_ID",
    },
}

节点

为了更好地组织,该插件被划分为 API 节点。

gpgs.achievements

gpgs.leaderboards

gpgs.players

gpgs.events

gpgs.snapshots

gpgs.*

概览

这是该插件的基本 API 节点。它管理与 Google 服务器的连接、身份验证和常规 SDK 任务。

函数

gpgs.init()

gpgs.enableDebug()

gpgs.isConnected(listener)

gpgs.isAuthenticated()

gpgs.login(params)

gpgs.logout()

gpgs.getAccountName(listener)

gpgs.getServerAuthCode(params)

gpgs.loadImage(params)

事件

login

getAccountName

getServerAuthCode

loadGame

loadImage

类型

游戏