[Huawei Developers] Freemind R:
More information like this, you can visit HUAWEI Developer Forum​

Intro

In this article I would like to address the HMS topic in Unity Engine. Unity is widely used in the world of video game development. With the help of the plugin developed by EvilMindDevs the integration of the HMS sdk is easier. Although the documentation of the plugin is quite explicit in this tutorial i want to review the implementation within a game. The game is very simple, A car which we must control by swiping to right or left. When losing, a menu where we can login to our HMS account with the help of the plugin. Without further introduction let's go to the article.

Steps

1. Download the code from the repository

2. Create our application in AGC

3. Creating Keystore whitin Unity

4. Obtaining the SHA256 number

5. Finishing the configuration in AGC

6. Let's download the plugin

7. Setting up json Services

8. Adding data of our App to the Plugin

9. Adding the Account Manager prefab to the scene

10.Adding a button to the "End of Game" Canvas

11. Adding neccesary objects

12. Creating an AuthPara class to manage Authentication

1.-Download the repository code

https://github.com/ADX2099/Unity-HMSAUTH

2.- Create our application in AGC

To implement the plugin we must create an App on our console

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/000/429/0890052100000000429.20200709201136.86570866832784660195054125683519:50510715012936:2800:7368E95BD24AA1D094885D7B2DD20F97000F8A0D3E57796504D9B58C86C24AFF.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/000/429/0890052100000000429.20200709201136.86570866832784660195054125683519:50510715012936:2800:7368E95BD24AA1D094885D7B2DD20F97000F8A0D3E57796504D9B58C86C24AFF.png[/IMG]

Click on My apps

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/000/429/0890052100000000429.20200709201217.24370222361018981660520855441578:50510715012936:2800:C2572A446E3CFE767F2FB2CA3E5FD5A4FD6956D27E5CF295300D1176740CF1AB.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/000/429/0890052100000000429.20200709201217.24370222361018981660520855441578:50510715012936:2800:C2572A446E3CFE767F2FB2CA3E5FD5A4FD6956D27E5CF295300D1176740CF1AB.png[/IMG]

Choose New app and fill App data, this time we must select Game in App Category. Once the App is created, what we will do is go to the develop tab and place the name of our package. Choose the one that suits you best, within this tab is where we will find the necessary data to implement the plugin.

3.-Creating the Keystore in Unity

Now we have to open Unity and start to configure the project, to achieve this we must go to File -> Build Settings -> Player Settings

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/000/429/0890052100000000429.20200709201414.16136302408992293763677674608710:50510715012936:2800:140663219B045329AFAAD4465F3E16CB796E2CDCFB092997A5E82B410492B0B8.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/000/429/0890052100000000429.20200709201414.16136302408992293763677674608710:50510715012936:2800:140663219B045329AFAAD4465F3E16CB796E2CDCFB092997A5E82B410492B0B8.png[/IMG]

Within Player Settings we must look for the Publishing Settings tab and open the KeystoreManager

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/000/429/0890052100000000429.20200709201450.03838266710064471328098970933868:50510715012936:2800:1426843295A278F7CDD1C2950B49C31443468EFBBE20A0A0026D0D10C2CC0036.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/000/429/0890052100000000429.20200709201450.03838266710064471328098970933868:50510715012936:2800:1426843295A278F7CDD1C2950B49C31443468EFBBE20A0A0026D0D10C2CC0036.png[/IMG]

Create our keystore in the desired place

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/000/429/0890052100000000429.20200709201529.46345157493604200503548444610659:50510715012936:2800:11F4AB5420603F1F0E99F3319373374AEE292CA9018C6742CDD72ABBABB34163.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/000/429/0890052100000000429.20200709201529.46345157493604200503548444610659:50510715012936:2800:11F4AB5420603F1F0E99F3319373374AEE292CA9018C6742CDD72ABBABB34163.png[/IMG]

Fill the fields for our key

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/000/429/0890052100000000429.20200709201608.41497717461801003117691126702063:50510715012936:2800:58070FFD93774F22CEF54A0A106A410861A957F02E778CC77715304ACD05708A.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/000/429/0890052100000000429.20200709201608.41497717461801003117691126702063:50510715012936:2800:58070FFD93774F22CEF54A0A106A410861A957F02E778CC77715304ACD05708A.png[/IMG]

Done! We have generated our Key locate it in your Explorer

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/000/429/0890052100000000429.20200709201643.71262124140788713857939426338183:50510715012936:2800:41FE19E473D0955F99958F149AC84B33475C08A0FB6CC2385477F85433130510.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/000/429/0890052100000000429.20200709201643.71262124140788713857939426338183:50510715012936:2800:41FE19E473D0955F99958F149AC84B33475C08A0FB6CC2385477F85433130510.png[/IMG]

4.-Obtaining the number of SHA256

To obtain the SHA256 by console we must follow the following link

https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides-V5/signing-fingerprint-0000001050071709-V5

Remember that it is also recommended that you adjust your java PATH in the Windows environment variables if your computer has this system.

5.-Finishing setup in AGC

Once we have obtained our fingerprint, place it in the corresponding section in AGC

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/000/429/0890052100000000429.20200709201802.35862190968943067445464731699371:50510715012936:2800:480D31849A90D115E4FFA0B931FED121674D0CA755035A11970E11A372E8B90A.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/000/429/0890052100000000429.20200709201802.35862190968943067445464731699371:50510715012936:2800:480D31849A90D115E4FFA0B931FED121674D0CA755035A11970E11A372E8B90A.png[/IMG]

6.- Let's download the plugin

Our AGC App has been configured now we must download the Unity plugin. Let's go to the next link and download the ZIP.

https://github.com/EvilMindDevs/hms-unity-plugin

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/000/429/0890052100000000429.20200709201922.28319871650611815054909785008686:50510715012936:2800:B232C356C7F65CDECCC10DC59CABD76CBE1450943F734B8D5CA0F1684887978B.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/000/429/0890052100000000429.20200709201922.28319871650611815054909785008686:50510715012936:2800:B232C356C7F65CDECCC10DC59CABD76CBE1450943F734B8D5CA0F1684887978B.png[/IMG]

Once the plugin is downloaded, locate it in your File Explorer, because now we must import it into Unity. go to Assets-> Import Package->CustomPackage

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/000/429/0890052100000000429.20200709201955.78655675203111462153638964886351:50510715012936:2800:287D4E7EF368BE6B331D3A124A5324A2DE2CCD5C36B106EDCF0B495E049B42F1.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/000/429/0890052100000000429.20200709201955.78655675203111462153638964886351:50510715012936:2800:287D4E7EF368BE6B331D3A124A5324A2DE2CCD5C36B106EDCF0B495E049B42F1.png[/IMG]

Once the plugin is imported we will have the following folder structure

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/000/429/0890052100000000429.20200709202106.01798143214984513190643488293286:50510715012936:2800:B3BDB384FC13CA1FBE70AC2BA4BE0EAFF03CB041D27665F05F285D0BD17E931D.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/000/429/0890052100000000429.20200709202106.01798143214984513190643488293286:50510715012936:2800:B3BDB384FC13CA1FBE70AC2BA4BE0EAFF03CB041D27665F05F285D0BD17E931D.png[/IMG]

7.-Setting the json Services

Let's download the JSON Services of our App from AGC

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/000/429/0890052100000000429.20200709202136.20254238636369358357129026152849:50510715012936:2800:3AF34679E2CF0B9E7F8E319E1B0AA8912699F1745C2A6A8B66A0A7312C7AF20B.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/000/429/0890052100000000429.20200709202136.20254238636369358357129026152849:50510715012936:2800:3AF34679E2CF0B9E7F8E319E1B0AA8912699F1745C2A6A8B66A0A7312C7AF20B.png[/IMG]

Open the agconnect file and replace the information downloaded from your agconnect-services.json

8.-Adding data of our App to the Plugin we have to go to the Huawei menu -> App Gallery

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/000/429/0890052100000000429.20200709202223.32517531579094626832240171350836:50510715012936:2800:C2CE0128843901EA5A83C78ABCDBB56C868AE923B827697CD763579CEFF25E90.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/000/429/0890052100000000429.20200709202223.32517531579094626832240171350836:50510715012936:2800:C2CE0128843901EA5A83C78ABCDBB56C868AE923B827697CD763579CEFF25E90.png[/IMG]

As said in the beggining this information will be found in your App properties on AGC

We have to set up our parameters in the following fields.

9.- Adding the Account Manager prefab to the scene.

As mentioned in the documentation we must drag the desired prefab to our scene in Unity in this case we will use Account Manager so we add it to the root of our scene

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/000/429/0890052100000000429.20200709202408.53530083658936678542992647471399:50510715012936:2800:4251CC8CFFA319B4BED3CA569F2CE809BCE4C55BA56A1BBC879A706586A53CF6.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/000/429/0890052100000000429.20200709202408.53530083658936678542992647471399:50510715012936:2800:4251CC8CFFA319B4BED3CA569F2CE809BCE4C55BA56A1BBC879A706586A53CF6.png[/IMG]

10.- Add a button to the End of Game Canvas

For this example of how to use Account HMS service We will add a UI button within the canvas that is displayed at the end of the game, the purpose of this menu will be to display the authentication to Huawei.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/000/429/0890052100000000429.20200709202539.33281163950191202192852096833804:50510715012936:2800:C827C9C7DD1EC63BD06C334F572817EE9FE305866994C74A75FBA6A61AEE9D7A.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/000/429/0890052100000000429.20200709202539.33281163950191202192852096833804:50510715012936:2800:C827C9C7DD1EC63BD06C334F572817EE9FE305866994C74A75FBA6A61AEE9D7A.png[/IMG]

11.-Add necessary objects in the inspector

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/000/429/0890052100000000429.20200709202626.26957860529709424795816338193239:50510715012936:2800:43339F1CDDF80F70816685B42D4074414EEDCBE1CCCB5DDD284C290B68FEC6CF.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/000/429/0890052100000000429.20200709202626.26957860529709424795816338193239:50510715012936:2800:43339F1CDDF80F70816685B42D4074414EEDCBE1CCCB5DDD284C290B68FEC6CF.png[/IMG]

12.-Creating an Auth class to manage the login.

Within the game scripts I have created a class called AuthLogin where we will add the following code. This code will be necessary to call the AccountManager object. Don't forget to add it to the Button object too. As shown in the image above.

using HmsPlugin;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class AuthLogin : MonoBehaviour
{
public Button btnLogin;
public AccountManager myAccountManager;

// Start is called before the first frame update
void Start()
{
myAccountManager = GameObject.Find("AccountManager").GetComponent<AccountManager>();

Button btn = btnLogin.GetComponent<Button>();
btn.onClick.AddListener(TaskOnClick);

}

public void TaskOnClick()
{

if (myAccountManager)
{
myAccountManager.SignIn();
}
else
{
myAccountManager = GameObject.Find("AccountManager").GetComponent<AccountManager>();
}

}

// Update is called once per frame
void Update()
{

}

Documentation mentions that you execute the login method to start with the authentication but reviewing the class the only methods we have are Sign In and SignOut

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/000/429/0890052100000000429.20200709202804.44520199444941303182082774039698:50510715012936:2800:604513E89915111D48CEC8F1ACB6BFCDA2DCAF850B2D90CDCDBC227513EDD083.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/000/429/0890052100000000429.20200709202804.44520199444941303182082774039698:50510715012936:2800:604513E89915111D48CEC8F1ACB6BFCDA2DCAF850B2D90CDCDBC227513EDD083.png[/IMG]

Conclusion

With this little exercise we have learned how to implement the HMS plugin and start using HMS in Unity, I hope it helps you, the plugin also has the following Kits.