Unity integrates Huawei Game Services SDK method (2): Integrating the Unity-Plugins plug-in

In order to use Unity to easily and quickly integrate Huawei hms core sdk , some game developers have made a professional plug-in and integrated the plug-in into the unity project, saving the trouble of integrating the sdk by themselves , and calling the interface directly after importing.

The plugin supports unity 2018 , 2019 , 2020 , and 2021 versions respectively, using the 2.0-2018 branch code for the unity2018 version, and the master branch code for the 2019 , 2020 , and 2021 versions . Plugin link: https://github.com/EvilMindDevs/hms -unity-plugin

The import steps are as follows:

Select and download the corresponding .unitypackage version according to the local unity version , then open the local project and select  Assets> Import Package> Custom Package :

cke_4837.png

 Select the downloaded HMS Unity plug-  in in the file explorer , all selected by default. The Import  Unity  Package dialog will appear :

cke_19318.png

Hit import and when done, Unity  will deploy the  Unity  plugin to your Assets folder. The specific folders are the huawei directory and the StreamingAssets directory in Assets .

In order for the plugin to take effect, you also need to associate your project with the plugin. To integrate the game plugin, you need to associate the game service and the account service . The steps are as follows:

Select huawei>kit Settings to open the Hms Settings pop-up window:

cke_26707.png

When checking Game Service , Account will be checked automatically .

cke_41534.png

After checking it, close the pop-up window. You can see that HMSAccountManager and HMSGameManager instances are automatically created under Hierarchy in the project bar. Indicates that the association is successful, and the call interface can be implemented through the plug-in.

cke_48906.png

 

There are demo examples in the Huawei directory , you can quickly run the demo .

Before running the demo , you need to modify the package name to be consistent with the Huawei developer backend, and download the json file of the Huawei developer backend to replace the json file in the demo , and replace the path: Assets>StreamingAssets .

cke_56295.png

And modify the package name to be consistent with json , open:

cke_63857.png

Click on Player Settings on the page…

cke_71270.png

Select Player in the left column of the page , select Other Settings , check Override default Package Name , and enter the package name, as shown in the figure:

cke_78686.png

After replacing the package name and the corresponding json file, open the demo and run it. Game demo path: Assets>Huawei>demos>Game .

You can also import the plug-in yourself , and integrate the Huawei Game Service SDK according to the demo example , such as integrating the login interface:

Create a layout scene file in the assets directory and create a button:

cke_86148.png

Create a script file, call the login interface and bind the button click event. The interface code is as follows:

Implement the login-related interface methods registered by the plugin in the Start method.

void Start()
    {
        HMSAccountManager.Instance.OnSignInSuccess = OnSignInSuccess;
        HMSAccountManager.Instance.OnSignInFailed = OnSignInFailed;
    }
public void OnSignInSuccess(AuthAccount auth)
    {
        Debug.Log("sign success");
    }

public void OnSignInFailed(HMSException e)
    {
        Debug.LogError(e.Message);
    }

Then the interface can call the interface encapsulated by the plug-in.

public void signIn()
    {
        HMSAccountManager.Instance.SignIn();
}

Finally, run and test whether the interface is successful. If the interface is called successfully, the sign success log will be printed, as shown in the figure:

cke_106954.png

Other interface access is similar, you can refer to the demo integration by yourself, which will not be repeated here: https://github.com/EvilMindDevs/hms-unity-plugin

{{o.name}}
{{m.name}}

Guess you like

Origin my.oschina.net/u/4478396/blog/5526730