docs.unity3d.com
    Show / Hide Table of Contents

    游戏服务(HMS)

    简介

    本Unity软件包集成了华为Game Service游戏服务套件的功能

    如何在您的Unity项目中集成华为Game Services游戏服务能力?

    1. 从Unity Asset Store导入此华为HMS Core App Services SDK

    2.将以下配置文件添加到 Assets/Plugins/Android 中

    2.1 agconnect-services.json
    将此配置文件下载并放到您的应用中 请参阅华为AppGallery找到文件并下载。

    AgcConnectServices Json

    2.2 baseProjectTemplate.gradle
    添加AppGallery Connect plugin 以及 Maven repository

     ```
     allprojects {
         buildscript {
             repositories {**ARTIFACTORYREPOSITORY**
                 google()
                 jcenter()
                 maven { url 'https://developer.huawei.com/repo/' }
             }
    
             dependencies {
                 //如果您要更改Android Gradle插件版本,请确保它与Unity预装的Gradle版本兼容
                 //您可以在此处查看Unity预装了哪个Gradle版本 https://docs.unity.cn/cn/2019.4/Manual/android-gradle-overview.html
                 //请在此处查看官方的Gradle和Android Gradle插件兼容性列表 https://developer.android.com/studio/releases/gradle-plugin#updating-gradle
                 //要在Unity中指定自定义Gradle版本,请到"Preferences > External Tools",取消选中"Gradle Installed with Unity (recommended)" ,然后指定自定义Gradle版本的路径
                 classpath 'com.android.tools.build:gradle:3.4.0'
                 classpath 'com.huawei.agconnect:agcp:1.2.1.301'
                 **BUILD_SCRIPT_DEPS**
             }
         }
    
         repositories {**ARTIFACTORYREPOSITORY**
             google()
             jcenter()
             flatDir {
                 dirs "${project(':unityLibrary').projectDir}/libs"
             }
             maven { url 'https://developer.huawei.com/repo/' }
         }
     }
     ```
    

    2.3 launcherTemplate.gradle
    添加构建依赖

     ```
     dependencies {
         ...
         implementation 'com.huawei.agconnect:agconnect-core:1.2.0.300'
         implementation 'com.huawei.hms:base:4.0.1.300'
         implementation 'com.huawei.hms:hwid:4.0.1.300'
         implementation 'com.huawei.hms:game:4.0.1.300'
         ...
         }
     ```
    

    2.4 mainTemplate.gradle
    添加构建依赖

     ```
     dependencies {
         ...
         implementation 'com.huawei.agconnect:agconnect-core:1.2.0.300'
         implementation 'com.huawei.hms:base:4.0.1.300'
         implementation 'com.huawei.hms:hwid:4.0.1.300'
         implementation 'com.huawei.hms:game:4.0.1.300'
         ...
     **DEPS**}
     ```
    

    3. Huawei API 参考链接 与 集成开发流程

    3.1 Huawei API reference https://developer.huawei.com/consumer/cn/doc/development/HMSCore-References-V5/jos-games-0000001050121646-V5

    3.2 Huawei API integration guide https://developer.huawei.com/consumer/cn/doc/HMSCore-Guides-V5/dev-process-0000001050193900-V5

    4. 在您使用以下API 之前,请首先在您的华为开发者账号中对其进行正确配置

    https://developer.huawei.com/consumer/cn/doc/HMSCore-Guides-V5/config-agc-0000001050166285-V5#ZH-CN_TOPIC_0000001054452903__section122826183710

    4.1 Achievement成就 https://developer.huawei.com/consumer/en/doc/distribution/app/agc-add_achievement

    4.2 Event事件 https://developer.huawei.com/consumer/en/doc/distribution/app/agc-add_event

    4.3 Leaderboard排行榜 https://developer.huawei.com/consumer/en/doc/distribution/app/agc-add_leaderboard

    5. 示例项目

    您可以在此下载示例项目,其中您可以找到Game Services对应的示例场景。 首先确保您已经在华为平台上创建了HMS帐户和项目,在Unity将本示例项目构建到Android移动版上,您即可对配置进行对照参考、进行更改、或对不同的功能进行调试。

    如何使用示例

    在使用示例代码之前,请仔细阅读文档的集成部分,建议在完成以下操作后才运行示例代码:

    1. 请使用您自己的 agconnect-services.json 文件,您可以参考本文档中的第2.1节

    2. 需要在Keystore Manager变更您的签名文件 Build Settings > Player Settings > Publishing Settings > Project Keystore.

    3. 您可以继续在Player Setting里修改您自己的Company Name, Product Name, Version number, 等等内容。

    4. 请注意避免您的工程路径中包含中文路径,以防止不必要的报错。

    5. 请参考华为应用功能开发准备配置签名证书指纹。

    6. 如果需要测试成就,事件和排行榜功能,则需要参考本文档的第4部分进行配置。

    6. 主要更新日志

    2020-09-29

    • New: Add CheckUpdate , ShowUpdateDialog, ReleaseCallBack to check if there is a later version.
    • New: Add CancelAuthorization to revoke authorization on your app.
    • New: Add StartReadSms, RegisterSMSBroadcastReceiver, UnregisterSMSBroadcastReceiver to automatically read an SMS verification code.
    • New: Add GetCachePlayerId, SubmitPlayerEvent, GetPlayerExtraInfo,SavePlayerInfo.
    • New: Add GetThumbnail to obtain the data of an archive cover.
    • Fix: interfaces that are not working properly.

    7. API 参考列表

    游戏服务SDK 初始化

    HuaweiGameService.AppInit()

    初始化一个应用程序,这个方法需要在应用启动的时候被调用。

    HuaweiGameService.Init()

    应用程序调用Init 方法来初始化游戏。

    HuaweiGameService.CheckUpdate(ICheckUpdateListener listener)

    在启动和初始化应用程序后,或用户主动检查该应用程序更新的时候,检查该应用程序的新版本。

    • 参数

      • ICheckUpdateListener - 将运行的回调
    HuaweiGameService.ShowUpdateDialog(AndroidJavaObject jo, bool mustBtnOne)

    在启动和初始化应用程序后,或用户主动检查该应用程序更新的时候,检查该应用程序的新版本。

    • 参数

      • AndroidJavaObject - 检测更新信息。有关详情,请参考 ApkUpgradeInfo.
      • mustBtnOne - 提示用户是否需要强制更新,选项如下:
        • true: 应用程序更新弹出窗口仅显示更新按钮,用户必须更新应用程序。
        • false: 应用程序更新弹出窗口同时显示更新和取消按钮。用户可以点击取消按钮来取消更新。
    HuaweiGameService.ReleaseCallBack()

    释放回调以防止内存泄漏。您需要在 destroy 中调用此方法。对于静态内部类的方法,不需要调用此方法。

    Account 账号

    HuaweiGameService.Login(ILoginListener listener)

    开始登录流程,返回并缓存用户信息。

    • 参数

      • ILoginListener - 将运行的回调
    HuaweiGameService.SilentSignIn(ILoginListener listener)

    登录回调包含此用户的signInAccountProxy登录帐户代理或错误信息。如果没有用户以登录,可尝试在不显示任何用户界面的情况下登录该用户。

    • 参数
      • ILoginListener - 将运行的回调
    HuaweiGameService.SignOut(ILoginListener listener)

    退出当前已有的登录用户,同时删除缓存的登录账号信息

    • 参数

      • ILoginListener - 将运行的回调
    ILoginListener
    public interface ILoginListener
    {
        //signInAccountProxy - 包含已登录用户基本帐户信息的类
        void OnSuccess(SignInAccountProxy signInAccountProxy);
    
        void OnSignOut();
    
        void OnFailure(int code, string message);
    }
    
    HuaweiGameService.CancelAuthorization(ICancelAuthListener listener)

    为提高隐私的安全性,允许用户撤消对您应用的授权

    • 参数

      • ICancelAuthListener - 将运行的回调
    HuaweiGameService.StartReadSms(IStartReadSmsListener listener)

    如果您的应用程序要求用户输入手机号码并使用SMS验证码来验证用户身份,则可以集成ReadSmsManager服务,以便您的应用程序可以自动读取SMS验证码,而无需申请SMS读取权限。

    • 参数

      • IStartReadSmsListener - 将运行的回调
    HuaweiGameService.RegisterSMSBroadcastReceiver(ISMSReceive receive)

    当用户的设备收到验证消息时,HMS Core(APK)会将其显式广播到您的应用程序,其中包含消息文本。您的应用可以通过接收广播来验证消息

    • 参数

      • ISMSReceive - 将运行的回调
    HuaweiGameService.UnregisterSMSBroadcastReceiver()

    注销获取SMS广播

    Achievement interface 成就界面

    展示成就
    HuaweiGameService.GetAchievementList(bool forceReload, IGetAchievementListListener listener)

    获取当前登录玩家的成就列表

    • 参数

      • forceReload - 表示从服务器或客户端获取成就列表,选项如下:
        true: server
        false: client

      • IGetAchievementListListener - 将运行的回调

    IGetAchievementListListener
    public interface IGetAchievementListListener
    {
        //achievementList - The list of achievements of the current player.
        void OnSuccess(List<Achievement> achievementList);
    
        void OnFailure(int code, string message);
    }
    
    HuaweiGameService.GetAchievementsIntent(IGetAchievementsIntentListener listener)

    在回调中返回一个Intent以显示游戏的成就

    • 参数
      • IGetAchievementsIntentListener - 将运行的回调
    IGetAchievementsIntentListener
    public interface IGetAchievementsIntentListener
    {
        //AndroidJavaClass: android.content.Intent, an Intent to show the list of achievements for a game.
        void OnSuccess(AndroidJavaObject intent);
    
        void OnFailure(int code, string message);
    }
    
    Revealing an Achievement
    HuaweiGameService.Reveal(string achievementId)

    向当前登录的玩家显示隐藏的成就,如果成就已被解锁,则将无效

    如果不需要立即知道接口结果,请使用此方法。 请注意,更新可能不会立即发送到服务器 如果需要获取API的执行结果,请参考 AsyncReveal(string achievementId, IRevealListener listener)

    • 参数

      • achievementId - 需要显示成就的ID
    HuaweiGameService.AsyncReveal(string achievementId, IRevealListener listener)

    异步获取回调,以向当前登录的玩家显示隐藏的成就。 如果成就已经可见,则将无效。

    这种形式的API将尝试立即在服务器上更新用户的成就,并返回执行结果。

    • 参数

      • achievementId - 需要显示成就的ID

      • IRevealListener - 将运行的回调

    IRevealListener
    public interface IRevealListener
    {
        void OnSuccess();
    
        void OnFailure(int code, string message);
    }
    
    Increasing Steps
    HuaweiGameService.Increment(string achievementId, int numSteps)

    按给定的步骤数来增加成就,首先成就必须是一个可增量的成就,达到最大步骤数后,就会自动解锁,后续任何进一步的增量将被忽略。

    如果不需要立即知道接口结果,请使用此方法。 请注意,更新可能不会立即发送到服务器。 如果需要获取API的执行结果,请参见 AsyncIncrement(string achievementId, int numSteps, IIncrementListener listener)

    • 参数

      • achievementId - 需要逐步增加成就的ID

      • numSteps - 要增加的步骤数,该值必须大于0。

    HuaweiGameService.AsyncIncrement(string achievementId, int numSteps, IIncrementListener listener)

    异步获取回调,以给定的步骤数来增加成就。成就必须属于可增量,达到最大步数后会自动解锁成就,任何进一步的增量将被忽略

    这种形式的API将尝试立即在服务器上更新用户的成就,并返回执行结果。

    • 参数

      • AchievementId - 需要逐步增加的成就的ID

      • numSteps - 需要增加的步骤数,该值必须大于0。

      • IIncrementListener - 将运行的回调。

    IIncrementListener
    public interface IIncrementListener
    {
        void OnSuccess(bool isSuccess);
    
        void OnFailure(int code, string message);
    }
    
    Setting Steps 设定步骤数
    HuaweiGameService.SetSteps(string achievementId, int numSteps)

    通过设置步骤数来实现成就。一旦成就达到设定最大步数,成就将自动解锁,并且任何后续的操作都将被忽略

    如果不需要立即得到接口结果,请使用此方法。 请注意,更新可能不会立即发送到服务器。 如果需要获取API的执行结果,请参见 HuaweiGameService.AsyncSetSteps(string achievementId, int numSteps, ISetStepsListener listener)

    • 参数

      • achievementId - 需要设置步骤作为成就的ID

      • numSteps - 要设置的步骤数,该值必须大于0

    HuaweiGameService.AsyncSetSteps(string achievementId, int numSteps, ISetStepsListener listener)

    异步获取回调,以给定的步骤数来增加成就。 达到最大步数后会自动解锁成就,任何进一步的增量将被忽略

    这种形式的API将尝试立即在服务器上更新用户的成就,并返回执行结果

    • 参数

      • achievementId - 需要设置步骤的成就的ID

      • numSteps - 需要设置的步骤数,该值必须大于0

      • ISetStepsListener - 将运行的回调

    ISetStepsListener
    public interface ISetStepsListener
    {
        //isSuccess - 值为 true 表示执行成功
                      值为 false 表示已成功调用API,但执行失败
                      如果执行失败,则需要检查成就ID和设置的步骤数是否正确
        void OnSuccess(bool isSuccess);
    
        void OnFailure(int code, string message);
    }
    
    Unlocking an Achievement
    HuaweiGameService.Unlock(string achievementId)

    为当前登录的玩家解锁成就,如果成就被隐藏,则将其显示给玩家

    如果不需要立即知道接口结果,请使用此方法 请注意,更新可能不会立即发送到服务器 如果需要获取API的执行结果,请参见 AsyncUnlock(string achievementId, IUnlockListener listener)

    • 参数

      • achievementId - 需要解锁成就的ID
    HuaweiGameService.AsyncUnlock(string achievementId, IUnlockListener listener)

    异步获取回调,以解锁当前登录的玩家的成就,如果成就被隐藏,则将其显示给玩家

    这种形式的API将尝试立即在服务器上更新用户的成就,并返回执行结果

    • 参数
      • achievementId - 需要解锁成就的ID
      • IUnlockListener - 将运行的回调
    IUnlockListener
    public interface IUnlockListener
    {
        void OnSuccess();
    
        void OnFailure(int code, string message);
    }
    

    leaderboards

    Submitting a Player’s Score
    HuaweiGameService.GetLeaderboardSwitchStatus(ILeaderboardSwitchStatusListener listener)

    获取排行榜开关设置,提示玩家是否同意将自己的分数报告给排行榜,首次登录时默认情况下禁用此开关

    • 参数

      • ILeaderboardSwitchStatusListener - 将运行的回调
    HuaweiGameService.SetLeaderboardSwitchStatus(int status, ILeaderboardSwitchStatusListener listener)

    设置排行榜开关

    • 参数

      • status - 排行榜开关的状态 0: off 1: on

      • ILeaderboardSwitchStatusListener - 将运行的回调

    ILeaderboardSwitchStatusListener
    public interface ILeaderboardSwitchStatusListener
    {
        //statusValue - 指示是否以异步模式返回排行榜开关设置
                        0: no
                        1: yes
        void OnSuccess(int statusValue);
    
        void OnFailure(int code, string message);
    }
    
    HuaweiGameService.SubmitScore(string leaderboardId, int score)

    将当前登录玩家的分数提交给排行榜

    如果不需要立即知道接口结果,请使用此方法 请注意,更新可能不会立即发送到服务器 如果需要获取API的执行结果,请参见 AsyncSubmitScore(string leaderboardId, int score, ISubmitScoreListener listener)

    • 参数

      • leaderboardId - 排行榜ID

      • score - 当前玩家的分数

    HuaweiGameService.AsyncSubmitScore(string leaderboardId, int score, ISubmitScoreListener listener)

    将当前登录玩家的分数提交给排行榜,此方法将异步获取回调

    这种形式的API将尝试立即将分数提交给服务器,并返回执行结果

    • 参数

      • leaderboardId - 排行榜ID

      • score - 当前玩家的分数

      • ISubmitScoreListener - 将运行的回调

    ISubmitScoreListener
    public interface ISubmitScoreListener
    {
        //scoreSubmission - 提交结果
        void OnSuccess(ScoreSubmission scoreSubmission);
    
        void OnFailure(int code, string message);
    }
    
    HuaweiGameService.SubmitScore(string leaderboardId, int score, string scoreTag)

    将当前登录玩家的分数提交给排行榜

    如果不需要立即知道接口结果,请使用此方法 请注意,更新可能不会立即发送到服务器 如果需要获取API的执行结果,请参见 AsyncSubmitScore(string leaderboardId, int score, string scoreTag, ISubmitScoreListener listener)

    • 参数

      • leaderboardId - 排行榜ID

      • score - 当前玩家的分数

      • scoreTag - 分数标签,只支持字母,数字,下划线(_)和连字符 (-)

    HuaweiGameService.AsyncSubmitScore(string leaderboardId, int score, string scoreTag, ISubmitScoreListener listener)

    将已登录玩家的分数提交给当前排行榜,此方法将异步获取回调

    这种形式的API将尝试立即将分数提交给服务器,并返回执行结果

    • 参数

      • leaderboardId - 排行榜ID

      • score - 当前玩家的分数

      • scoreTag - 分数标签,只支持字母,数字,下划线(_)和连字符 (-)

      • ISubmitScoreListener - 将运行的回调

    Displaying the Leaderboard List Screen
    HuaweiGameService.GetAllLeaderboardsIntent(IGetLeaderboardIntentListener listener)

    获得排行榜列表屏幕的 Intent 对象。

    • 参数
      • IGetLeaderboardIntentListener - 将运行的回调
    HuaweiGameService.GetLeaderboardIntent(string leaderboardId, IGetLeaderboardIntentListener listener)

    在所有时间范围内获取指定排行榜的屏幕 Intent 对象。

    • 参数

      • leaderboardId - 要获取其数据的排行榜的ID

      • IGetLeaderboardIntentListener - 将运行的回调

    HuaweiGameService.GetLeaderboardIntent(string leaderboardId, int timeSpan, IGetLeaderboardIntentListener listener)

    在指定的时间范围内获取指定排行榜的屏幕 Intent 对象。

    • 参数

      • leaderboardId - 要获取其数据的排行榜的ID

      • timeSpan - 检索数据的时间跨度
        0: 获得每日排行榜 1: 获得每周排行榜 2: 获得历史排行榜

      • IGetLeaderboardIntentListener - 将运行的回调

    IGetLeaderboardIntentListener
    public interface IGetLeaderboardIntentListener
    {
        //AndroidJavaClass: android.content.Intent - 显示游戏排行榜或排行榜列表
        void OnSuccess(AndroidJavaObject intent);
    
        void OnFailure(int code, string message);
    }
    
    HuaweiGameService.GetLeaderboardsData(bool isRealTime, IGetLeaderboardsListener listener)

    获取所有排行榜数据,您可以指定是从服务器还是从本地缓存获取数据

    • 参数

      • isRealTime - 指示是否从服务器获取排行榜数据 true: 从服务器获取数据 false: 从本地缓存中获取数据

      • IGetLeaderboardsListener - 将运行的回调

    IGetLeaderboardListener
    public interface IGetLeaderboardsListener
    {
        //leaderboards - 此游戏的排行榜元数据列表
        void OnSuccess(List<LeaderboardProxy> leaderboards);
    
        void OnFailure(int code, string message);
    }
    
    HuaweiGameService.GetLeaderboardData(string leaderboardId, bool isRealTime, IGetLeaderboardListener listener)

    获取指定排行榜的数据,您可以指定是从服务器还是从本地缓存获取数据

    • 参数

      • leaderboardId - 要为其获取数据的排行榜ID

      • isRealTime - 指示是否从服务器获取排行榜数据 true: 从服务器获取数据 false: 从本地缓存中获取数据

      • IGetLeaderboardListener - 将运行的回调

    IGetLeaderboardListener
    public interface IGetLeaderboardListener
    {
        //leaderboardProxy - 由排行榜Id指定的排行榜数据。
        void OnSuccess(LeaderboardProxy leaderboardProxy);
    
        void OnFailure(int code, string message);
    }
    
    Displaying Scores 显示分数
    HuaweiGameService.GetLeaderboardTopScores(string leaderboardId, int timeSpan, int maxResults, bool isRealTime, IGetLeaderboardScoresListener listener)

    获取排行榜最高分

    • 参数

      • leaderboardId - 要获取其数据的排行榜ID

      • timeSpan - 检索数据的时间跨度
                           0: daily  1: weekly  2: all-time

      • maxResults - 每页上的最大记录数,整数形式,取值范围1〜200

      • isRealTime - 指示是否从服务器获取排行榜数据 true: 从服务器获取数据 false: 从本地缓存中获取数据

      • IGetLeaderboardScoresListener - 将运行的回调

    IGetLeaderboardScoresListener
    public interface IGetLeaderboardScoresListener
    {
        //leaderboardScores - 指定排行榜上的分数列表
        void OnSuccess(LeaderboardScores leaderboardScores);
    
        void OnFailure(int code, string message);
    }
    
    HuaweiGameService.GetLeaderboardTopScores(string leaderboardId, int timeSpan, int maxResults, long offset, int pageDirection, IGetLeaderboardScoresListener listener)

    获取排行榜最高分

    • 参数

      • leaderboardId - 要获取其数据的排行榜ID。

      • timeSpan - 检索数据的时间跨度                    0: daily  1: weekly  2: all-time

      • maxResults - 每页的最大记录数,整数形式,取值范围是1〜21

        -偏移量-。

        -pageDirection-。

      • offset - 从偏移量指定的位置获取数据页,offset的值必须是大于或等于0的整数

      • pageDirection - 数据获取方向,当前仅支持数值0 指示已获取下一页的数据

      • IGetLeaderboardScoresListener - 将运行的回调

    HuaweiGameService.GetCurrentPlayerLeaderboardScore(string leaderboardId, int timeSpan, IGetLeaderboardScoreListener listener)

    获取在指定时间范围内的指定排行榜上玩家的分数

    • 参数

      • leaderboardId - 要为其获取数据的排行榜ID

      • timeSpan - 检索数据的时间跨度                    0: daily  1: weekly  2: all-time

      • IGetLeaderboardScoreListener - 将运行的回调

    IGetLeaderboardScoreListener
    public interface IGetLeaderboardScoreListener
    {
        //leaderboardScore - 由排行榜Id指定的排行榜已登录玩家的分数
        void OnSuccess(LeaderboardScore leaderboardScore);
    
        void OnFailure(int code, string message);
    }
    
    HuaweiGameService.GetPlayerCenteredLeaderboardScores(string leaderboardId, int timeSpan, int maxResults, bool isRealTime, IGetLeaderboardScoresListener listener)

    获得排行榜的分数,并在中间位置显示当前玩家的分数,可以从本地缓存中获取数据,例如,某个玩家在排行榜上排名第五,则可以使用此方法获取当前玩家之前和之后指定数量的玩家的得分

    • 参数

      • leaderboardId - 要获取其数据的排行榜ID。

      • timeSpan - 检索数据的时间跨度                    0: daily  1: weekly  2: all-time

      • maxResults - 每页上的最大记录数,整数形式,取值范围是1〜21

      • isRealTime - 提示是否从服务器获取排行榜数据 true: 从服务器获取数据
        false: 从本地缓存中获取数据

      • IGetLeaderboardScoresListener - 将运行的回调

    HuaweiGameService.GetPlayerCenteredLeaderboardScores(string leaderboardId, int timeSpan, int maxResults, long offset, int pageDirection, IGetLeaderboardScoresListener listener)

    获得排行榜的分数,并在中间位置显示当前玩家的分数,只能从服务器获取数据

    • 参数

      • leaderboardId - 要获取其数据的排行榜ID

      • timeSpan - 检索数据的时间跨度                    0: daily  1: weekly  2: all-time

      • maxResults - 每页上的最大记录数, 整数形式,取值范围是1〜21

      • offset - 从offset指定的位置获取一页数据,offset的值必须是大于或等于0的整数

      • pageDirection - Data obtaining direction. 0: next page. 1: previous page

      • IGetLeaderboardScoresListener - 将运行的回调

    HuaweiGameService.GetMoreLeaderboardScores(string leaderboardId, long offset, int maxResults, int pageDirection, int timeSpan, IGetLeaderboardScoresListener listener)

    在分页模式下在排行榜上获取分数

    • 参数

      • leaderboardId - 要获取其数据的排行榜ID

      • offset - 从offset指定的位置获取一页数据,offset的值必须是大于或等于0的整数

      • maxResults - 每页上的最大记录数, 整数形式,取值范围是1〜21

      • pageDirection - Data obtaining direction. 0: next page. 1: previous page

      • timeSpan - 检索数据的时间跨度                    0: daily  1: weekly  2: all-time

      • IGetLeaderboardScoresListener - 将运行的回调

    events 事件

    Submitting Events 提交事件
    HuaweiGameService.EventIncrement(string eventId, int incrementAmount)

    按给定的步骤数和指定的eventId递增事件。 事件增量在本地缓存,并分批刷新到服务器

    • 参数

      • eventId - 要提交事件的ID

      • incrementAmount - 现有事件值的增量

    Obtaining Events 获得事件
    HuaweiGameService.GetEventList(bool forceReload, IGetEventListListener listener)

    获取当前玩家的所有事件数据

    • 参数

      • forceReload - 指示是加载存储在服务器上还是本地缓存的事件列表 true: server  false: local cache

      • IGetEventListListener - 将运行的回调

    HuaweiGameService.GetEventListByIds(bool forceReload, string[] eventIds, IGetEventListListener listener)

    Gets event list by specified event IDs.

    • 参数

      • forceReload - 指示是加载存储在服务器上还是本地缓存的事件列表 true: server  false: local cache

      • eventIds - 要获取的事件ID,该值是一个字符串数组

      • IGetEventListListener - 将运行的回调

    IGetEventListListener
    public interface IGetEventListListener
    {   
        //eventList - The list of event data.
        void OnSuccess(List<EventProxy> eventList);
    
        void OnFailure(int code, string message);
    }
    

    extras

    Obtaining current Player
    HuaweiGameService.GetCurrentPlayer(bool isRealTime, IGetPlayerListener listener)

    获取当前登录玩家的Player对象

    • 参数

      • IGetPlayerListener - 将运行的回调
    IGetPlayerListener
    public interface IGetPlayerListener
    {
        //player - 有关玩家的特定信息
        void OnSuccess(Player player);
    
        void OnFailure(int code, string message);
    }
    
    HuaweiGameService.GetCachePlayerId(IGetCachePlayerIdListener listener)

    获取当前玩家本地缓存的玩家ID

    • 参数

      • IGetCachePlayerIdListener - 将运行的回调
    Game Addiction Prevention
    HuaweiGameService.SubmitPlayerEvent(string playerId, string eventId, string evnetType, ISubmitPlayerEventListener listener)

    当玩家进入或退出游戏时报告事件

    • 参数

      • playerId - 当前玩家ID
      • eventId - 玩家事件ID
        • 当 eventType 是 GAMEBEGIN, 传一个随机数作为值给到 eventId. 该数值在应用程序中必须唯一,并且最多可以包含64个字符
        • 当 eventType 是 GAMEEND, pass the transactionId returned after submitPlayerEvent is called when a player enters a game as the value of eventId.
      • eventType - Event type. The options are as follows:
        • GAMEBEGIN: A player enters your game.
        • GAMEEND: A player exits your game.
      • ISubmitPlayerEventListener - 将运行的回调
    HuaweiGameService.GetPlayerExtraInfo(string transactionId, IGetPlayerExtraInfoListener listener)

    获取有关玩家的其他信息

    • 参数

      • transactionId - Transaction ID returned by Huawei game server after an app calls the submitPlayerEvent method to report a player event of entering a game.

        If a transaction ID exists, the ID is passed. If a transaction ID does not exist, null is passed.

      • IGetPlayerExtraInfoListener - 将运行的回调

    HuaweiGameService.SavePlayerInfo(AndroidJavaObject jo, ISavePlayerInfoListener listener)

    存储有关游戏中玩家的信息,例如关卡和区域

    • 参数

      • AndroidJavaObject - AppPlayerInfo, Details about a player in a game.
      • ISavePlayerInfoListener - 将运行的回调
    Obtaining Player Statistics
    HuaweiGameService.GetGamePlayerStatistics(bool isRealTime, IGetPlayerStatisticsListener listener)

    异步获取当前玩家的统计信息,可以从本地缓存或服务器获取统计信息

    • 参数

      • isRealTime - 指示是否从服务器获取数据
        true: 从服务器获取数据
        false: 从本地缓存中获取数据 如果没有本地缓存或缓存超时,将从游戏服务器获取数据

      • IGetPlayerStatisticsListener- 将运行的回调

    IGetPlayerStatisticsListener
    public interface IGetPlayerStatisticsListener
    {
        //playerStatistics - The statistics about the current player.
        void OnSuccess(PlayerStatistics playerStatistics);
    
        void OnFailure(int code, string message);
    }
    
    Obtaining Game Information
    HuaweiGameService.GetGame(IGetGameListener listener)

    从服务器异步获取有关当前游戏的信息,如果获取失败,则获取本地缓存的信息

    • 参数
      • IGetGameListener - 将运行的回调
    IGetGameListener
    public interface IGetGameListener
    {
        //game - The information about the current game.
        void OnSuccess(Game game);
    
        void OnFailure(int code, string message);
    }
    
    HuaweiGameService.GetLocalGame(IGetGameListener listener)

    从本地缓存异步获取有关当前游戏的信息

    • 参数

      • IGetGameListener - 将运行的回调
    FloatWindow
    HuaweiGameService.ShowFloatWindow()

    显示浮动窗口,建议您在游戏屏幕的onResume方法中调用此API

    HuaweiGameService.HideFloatWindow()

    隐藏浮动窗口。 建议您在onPause中调用此API以隐藏游戏浮动窗口,仅在调用showFloatWindow方法以显示游戏浮动窗口之后,才能调用此API

    Snapshot preparation
    HuaweiGameService.GrantDriveAccess()

    如果需要使用drive 功能,请先调用此方法,然后再调用登录方法

    HuaweiGameService.GetLimitThumbnailSize(ILimitSizeListener listener)

    获取服务器允许的快照封面文件的最大尺寸

    • 参数

      • ILimitSizeListener - 将运行的回调
    HuaweiGameService.GetLimitDetailsSize(ILimitSizeListener listener)

    获取服务器允许的快照文件的最大尺寸

    • 参数

      • ILimitSizeListener - 将运行的回调
    ILimitSizeListener
    public interface ILimitSizeListener
    {
        void OnSuccess(int limitSize);
    
        void OnFailure(int code, string message);
    }
    
    Creating a snapshot
    HuaweiGameService.AddSnapshot(SnapshotContent snapshot, SnapshotChange snapshotChange, bool isSupportCache,IGetSnapshotDataListener listener)

    该API异步提交SnapshotChange中所有对Snapshot所做的修改以及加载SnapshotData,一旦更改在本地同步并且此数据的后台同步被请求,此方法返回的任务即完成。

    • 参数

      • snapshot - 包含快照文件内容的快照对象

      • snapshotChange - 包含快照元数据更改的SnapshotChange对象

      • isSupportCache - 提示是否在网络异常时本地缓存数据并在网络恢复后提交数据 true: yes false: no

      • IGetSnapshotDataListener - 将运行的回调

    IGetSnapshotDataListener
    public interface IGetSnapshotDataListener
    {
        //snapshotData - The metadata of a saved game.
        void OnSuccess(SnapshotData snapshotData);
    
        void OnFailure(int code, string message);
    }
    
    Displaying Snapshots
    HuaweiGameService.GetShowArchiveListIntent(string title, bool allowAddBtn, bool allowDeleteBtn, int maxArchive,IGetShowSnapshotListIntentListener listener)

    获取应用的 Intent 对象以加载保存游戏列表页面

    • 参数

      • title - UI上显示的存档名称

      • allowAddBtn - 提示是否允许添加档案的按钮,选项如下:

        true: yes
        false: no

      • allowDeleteBtn - 提示是否允许删除档案的按钮,选项如下:

        true: yes
        false: no

      • maxArchive - 可以显示的最大归档数,值 -1 表示所有归档

      • IGetShowSnapshotListIntentListener - 将运行的回调

    HuaweiGameService.GetSnapshotDataList(bool isRealTime, IGetAllSnapshotDataListener listener)

    获取当前玩家的所有 snapshot 元数据,可以从本地缓存中获取数据

    • 参数

      • isRealTime - 指示是否从服务器获取数据
        true: 从服务器获取数据
        false: 从本地缓存中获取数据 如果没有本地缓存或缓存超时,将从服务器获取数据

      • IGetAllSnapshotDataListener - 将运行的回调

    IGetAllSnapshotDataListener
    public interface IGetAllSnapshotDataListener
    {
        //snapshotData - List of metadata for saved game.
        void OnSuccess(List<SnapshotData> allSnapshotData);
    
        void OnFailure(int code, string message);
    }
    
    HuaweiGameService.GetThumbnail(string archiveId, IGetCoverImageListener listener)

    获取存在的存档cover的数据

    • 参数

      • archiveId - Archive ID of the cover to be obtained.

      • IGetCoverImageListener - 将运行的回调

    IGetCoverImageListener
    public interface IGetCoverImageListener
    {
        //AndroidJavaClass:android.graphics.Bitmap convert to Base64 string
        void OnSuccess(string coverImage);
    
        void OnFailure(int code, string message);
    }
    
    loading a snapshot
    HuaweiGameService.LoadSnapshotContents(string snapshotId, int conflictPolicy, IGetSnapshotResultListener listener)

    根据snapshot ID读取snapshot 元数据。 可以指定冲突解决策略

    • 参数

      • snapshotId - ID of the snapshot metadata to be read.

      • conflictPolicy - 解决冲突的政策 -1: 服务器无法解决冲突,您需要使用 updateSnapshot 方法解决冲突
        1: 以播放时间较长的快照用于解决两个冲突快照之间的冲突 2: 以后来修改的快照用于解决两个冲突的快照之间的冲突
        3: 以进度快的快照用于解决两个冲突的快照之间的冲突

      • IGetSnapshotResultListener - 将运行的回调

    IGetSnapshotResultListener
    public interface IGetSnapshotResultListener
    {
        //snapshotResult - The result of attempting to open a snapshot or resolve a conflict from a previous attempt.
        void OnSuccess(SnapshotResult snapshotResult);
    
        void OnFailure(int code, string message);
    }
    
    HuaweiGameService.LoadSnapshotContents(SnapshotData SnapshotData, IGetSnapshotResultListener listener)

    读取基于snapshotData对象的快照元数据。如果在读取过程中发生冲突,请首先解决冲突

    • 参数

      • snapshotData - snapshotData对象,用于读取存档元数据
      • IGetSnapshotResultListener - 将运行的回调
    HuaweiGameService.LoadSnapshotContents(SnapshotData snapshotData, int conflictPolicy, IGetSnapshotResultListener listener)

    基于snapshotData对象读取快照元数据。 可以指定冲突解决策略

    • 参数
      • snapshotData - snapshotData对象,用于读取存档元数据
      • conflictPolicy - 冲突解决策略 -1: 服务器无法解决冲突,您需要使用updateSnapshot方法解决冲突
        1: 具有较长播放时间的快照用于解决两个冲突的快照之间的冲突 2: 之后修改的快照用于解决两个冲突的快照之间的冲突
        3: 进度快的快照用于解决两个冲突的快照之间的冲突
      • IGetSnapshotResultListener - 将运行的回调
    Updating a snapshot
    HuaweiGameService.UpdateSnapshot(Snapshot snapshot, IGetSnapshotResultListener listener)

    使用快照数据异步解决数据冲突,此方法将冲突的快照数据替换为指定的快照

    • 参数

      • snapshot - 用于解决冲突的快照对象

      • IGetSnapshotResultListener - 将运行的回调

    HuaweiGameService.UpdateSnapshot(string snapshotId, SnapshotChange snapshotChange, SnapshotContent snapshotContent, IGetSnapshotResultListener listener)

    使用修改后的快照元数据和快照文件内容来异步解决数据冲突,此方法用指定的 SnapshotChange 和 SnapshotContent 替换冲突的快照数据

    • 参数

      • snapshotId - 需要解决冲突的快照的ID

      • snapshotChange - 用于解决冲突的存档元数据对象

      • snapshotContent - 快照文件对象的内容,用于解决冲突

      • IGetSnapshotResultListener - 将运行的回调

    Deleting a snapshot
    HuaweiGameService.DeleteSnapshot(SnapshotData snapshotData, IDeleteSnapshotListener listener)

    删除快照,包括服务器上和本地缓存中的快照,根据快照ID删除服务器上的数据,并根据快照名称删除本地缓存中的数据

    • 参数

      • snapshotData - 包含要删除快照元数据的 SnapshotData 对象

      • IDeleteSnapshotListener - 将运行的回调

    IDeleteSnapshotListener
    public interface IDeleteSnapshotListener
    {
        snapshotId - ID of the snapshot.
        void OnSuccess(string snapshotId);
    
        void OnFailure(int code, string message);
    }
    
    Back to top Copyright © 2020 Unity Technologies
    Generated by DocFX
    on Friday, December 4, 2020