• Introducing XDA Computing: Discussion zones for Hardware, Software, and more!    Check it out!
  • Fill out your device list and let everyone know which phones you have!    Edit Your Device Inventory

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

Search This thread

Mayism

Senior Member
Nov 5, 2020
130
25
github.com
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:
  • Huawei GameService.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:

https://docs.unity.cn/cn/Packages-cn/[email protected]/manual/appgallery.html#7-api-references-list

Sign-in Process
According to Huawei’s restrictions on joint operations games (https://developer.huawei.com/consum...ry-connect-Guides/appgallerykit-devguide-game), 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: 5.0.4.301
HUAWEI AppGallery version: 11.0.2.302
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.

0*ocsZzcyz1p0W8owq.png
Test steps
1. Start the demo. The following page is displayed.
0*F_1UjfVaHfzvMNk0.png

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.
0*bdBbMIaIgpctDUj3.png

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.
0*4XBey5FFc7_p7mmN.png

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

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.
0*lCG-wcMhYpG45h7i.png

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

https://developer.huawei.com/consumer/en/doc/development/HMS-References/verify-login-signature

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.

0*PPjf3hbLK10mZxvD.png

HuaweiGameService.SignOut(ILoginListener listener)

Click signOut. The following information is displayed.

0*jIlPoUSYF5ebCWvx.png

HuaweiGameService.CancelAuthorization(ICancelAuthListener listener)

Click cancelAuthorization. The following information is displayed.

0*iGOfn6NJt-0UK3MF.png

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

0*ZKZn0cilsd0wQgGa.png