Initializing a Huawei Game and Implementing HUAWEI ID Sign-in Using Unity


These posts have shown the first few steps of developing a Unity-based game:

So far, you are able to run a game demo provided by Unity.

This post can help you further test the demo to see whether it can:

  • Complete some of the initialization operations.
  • Support HUAWEI ID sign-in and obtain player information.

After the demo test, you can write your own code by referring to the demo.

APIs provided by Unity:

APIs for game initialization:

  • HuaweiGameService.AppInit()
  • HuaweiGameService.Init()

APIs for game sign-in:

  • HuaweiGameService.Login(ILoginListener listener)
  • HuaweiGameService.SilentSignIn(ILoginListener listener)
  • HuaweiGameService.SignOut(ILoginListener listener)
  • HuaweiGameService.CancelAuthorization(ICancelAuthListener listener)

APIs for obtaining player information:

  • HuaweiGameService.GetCurrentPlayer(bool isRealTime, IGetPlayerListener listener)

For details about these APIs, see the official documentation of Unity:

Process

According to Huawei’s restrictions on joint operations games (, if your game will be:

  • Released in the Chinese mainland, call the following APIs:

AppInit > Init > login > getCurrentPlayer

  • Released outside the Chinese mainland only, the following APIs are optional:

AppInit > Init > login > getCurrentPlayer

HUAWEI ID sign-in is also optional.

In this example, I was going to release an app in the Chinese mainland, so I called the related APIs.

Demo Test

Test environment requirements

Device: A Huawei phone running EMUI 10.0.0, with Android 10

HMS Core (APK) version:

HUAWEI AppGallery version:

Unity version: 2020.1.2f1c1

You can obtain the demo code by referring to the following file. When an API is called, Unity displays a message indicating the calling result, which is very convenient for you to locate faults.

Test steps

1. Start the demo. The following page is displayed.

By default, the HuaweiGameService.AppInit() API is called during app launch. The preceding message indicates that the API is successfully called.

2. Click Init. The following information is displayed.

Note: For a joint operations game, this API needs to be called when the game is launched, as required by Huawei. Unity’s demo provides a button for you to call the API.

3. Click Login, then login. The HUAWEI ID sign-in page is displayed.

Click Authorise and log in. A greeting banner and logs are displayed, indicating that the sign-in is successful.

Note: Ensure that the greeting banner is displayed, or your joint operations game may be rejected during app review.

4. Click getCurrentPlayer. The following information indicates that the player information API is called successfully.

For details about how to verify the player information, please check the official documentation:

The game sign-in is complete when the player information is approved.

Other optional APIs:

HuaweiGameService.SilentSignIn(ILoginListener listener)

Click silentSignIn. The following information indicates that the API is called successfully.

HuaweiGameService.SignOut(ILoginListener listener)

Click signOut. The following information is displayed.

HuaweiGameService.CancelAuthorization(ICancelAuthListener listener)

Click cancelAuthorization. The following information is displayed.

Click login again. The sign-in page is launched again, indicating that the authorization is canceled.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store