Intermediate: How to Integrating the Huawei Game Service in Unity Game

Lokesh Suryan
4 min readMay 13, 2021

Introduction

In this article, we will cover Integration of Huawei Kit in Unity Project using Official Plugin (Huawei HMS Core App Services). Here we will cover below Kits. With Huawei Game Service, you will have access to a range of development capabilities. You can promote your game quickly and efficiently to Huawei’s vast user base by users sign in with their Huawei IDs. You can also use the service to quickly implement achievements, game events, and game addiction prevention functions, build basic game capabilities at a low cost, and perform in-depth game operations based on user and content localization.

Game Service provides the following basic functions for your game apps, with which you can quickly build basic game capabilities.

  • Game Service Login
  • Achievements
  • Leader Board Data
  • Current Player Info
  • Game Event begin and end

Development Overview

You need to install Unity software and I assume that you have prior knowledge about the unity and C#.

Hardware Requirements

  • A computer (desktop or laptop) running Windows 10.
  • A Huawei phone (with the USB cable), which is used for debugging.

Software Requirements

  • Java JDK installation package.
  • Unity software installed.
  • Visual Studio/Code installed.
  • HMS Core (APK) 4.X or later.

Follows the steps.

1. Create Unity Project.

  • Open unity Hub.
  • Click NEW, select3D, Project Name and Location.
  • Click CREATE, as follows:

2. Click Asset Store, search Huawei HMS Core App Servicesand click Import, as follows.

3. Once import is successful, verify directory in Assets> Huawei HMS Core App Services path, as follows.

4. Choose Edit > Project Settings > Player and edit the required options in Publishing Settings, as follows.

5. Generate a SHA-256 certificate fingerprint.

To generating SHA-256 certificate fingerprint use below command.

6. Download agconnect-services.json and copy and paste to Assets > Plugins > Android, as follows.

7. Choose Project Settings > Player and update package name.

8. Open LauncherTemplate.gradle and add below lines.

9. Open “baseProjectTemplate.gradle” and add lines, as follows.

10. Open “mainTemplate.gradle” and add lines, as follows.

11. Open AndroidManifest file and add below permissions.

12. Create Scripts folder and create a class.

HmsGameService.cs

AndroidManifest.xml

13. Follow the steps, as shown in image:

a. Assign HmsGameService script to Canvas.

b. Select Button and add onclick event.

c. Assign button to button handler.

14. Onclick Button Handler you find your script HmsGameService (As per your script name) and attach method as per below screen shot.

15. To build apk and run in device, choose File > Build Settings > Build for apk or Build and Run into connected device.

Result

  1. Click on Login Button you can see, it will login into game service as per below screenshot.

2. Click on Player Info, Leader Board and Achievement button you and see result as per below screenshot.

Tips and Tricks

  • Always use the latest version of the library.
  • Add agconnect-services.json file without fail.
  • Add SHA-256 fingerprint without fail.
  • Make sure dependencies added in build files.
  • Add Achievements and LeaderBoard details before run.

Conclusion

We have learnt integration of HMS Game Service Kit into Unity Game development. You have successfully built a game app and learned how to.

  • Use Huawei Game Service.
  • Use Huawei Game Service to develop the game sign-in function.
  • Use Huawei Game Service to develop the game addiction prevention function.

Thanks for reading the article, please do like and comment your queries or suggestions.

References

Game Service:

https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/introduction-0000001050121216?ha_source=hms1

Unity Manual : https://docs.unity.cn/cn/Packages-cn/com.unity.huaweiservice@1.3/manual/gameservices.html

Original Source : https://forums.developer.huawei.com/forumPortal/en/topic/0202562799462830045?ha_source=hms1

--

--