Skip to content

EvilMindDevs/hms-reference-game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

Unity HMS + GMS Integrated Reference Game App

Unity Reference Game Application with GMS + HMS integration(Unity+HMS+GMS)

Hyper-casual / agility game

1. GMS Integration Guideline

1.1 Requirements

Current prerequisites on above link for unity project on firebase:

https://firebase.google.com/docs/unity/setup#prerequisites

Note: Since this project also include hms , minimum prerequistes should be considered for both GMS and HMS(section 2.1) together

1.2 Integrated GMS kits & services list :

  • Google Sign-In Unity Plugin
  • Firebase Cloud Messaging
  • Google Admob
  • Firebase Analytics
  • Firebase Crashlytics
  • Firebase Remoteconfig

1.3 GMS Kit integration resources used :

2. HMS Integration Guideline

Huawei Mobile Services Plugin

The HMS Unity plugin helps you integrate all the power of Huawei Mobile Services in your Unity game:

  • Huawei Account Kit
  • In App purchases: Consumable, non consumables and Subscriptions.
  • Ads: Interstitial, rewarded videos and banner
  • Push notifications
  • Game leaderboards and achievements
  • Huawei Anayltics kit
  • Crash Service
  • Remote Config

Requirements

Android SDK min 21 Net 4.x

Important

This plugin supports:

  • Unity version 2019, 2020 - Developed in Master Branch
  • Unity version 2018 - Developed in 2018 Branch

Make sure to download the corresponding unity package for the Unity version you are using from the release section

Troubleshooting

Please check our wiki page

Status

This is an ongoing project, currently WIP. Feel free to contact us if you'd like to collaborate and use Github issues for any problems you might encounter. We'd try to answer in no more than a working day.

Expected soon features

  • Native Ads Integration

Connect your game Huawei Mobile Services in 5 easy steps

  1. Register your app at Huawei Developer
  2. Import the Plugin to your Unity project
  3. Connect your game with the HMS Kit Managers

1 - Register your app at Huawei Developer

1.1- Register at Huawei Developer

1.2 - Create an app in AppGallery Connect.

During this step, you will create an app in AppGallery Connect (AGC) of HUAWEI Developer. When creating the app, you will need to enter the app name, app category, default language, and signing certificate fingerprint. After the app has been created, you will be able to obtain the basic configurations for the app, for example, the app ID and the CPID.

  1. Sign in to Huawei Developer and click Console.
  2. Click the HUAWEI AppGallery card and access AppGallery Connect.
  3. On the AppGallery Connect page, click My apps.
  4. On the displayed My apps page, click New.
  5. Enter the App name, select App category (Game), and select Default language as needed.
  6. Upon successful app creation, the App information page will automatically display. There you can find the App ID and CPID that are assigned by the system to your app.

1.3 Add Package Name

Set the package name of the created application on the AGC.

  1. Open the previously created application in AGC application management and select the Develop TAB to pop up an entry to manually enter the package name and select manually enter the package name.
  2. Fill in the application package name in the input box and click save.

Your package name should end in .huawei in order to release in App Gallery

Generate a keystore.

Create a keystore using Unity or Android Tools. make sure your Unity project uses this keystore under the Build Settings>PlayerSettings>Publishing settings

Generate a signing certificate fingerprint.

During this step, you will need to export the SHA-256 fingerprint by using keytool provided by the JDK and signature file.

  1. Open the command window or terminal and access the bin directory where the JDK is installed.

  2. Run the keytool command in the bin directory to view the signature file and run the command.

    keytool -list -v -keystore D:\Android\WorkSpcae\HmsDemo\app\HmsDemo.jks

  3. Enter the password of the signature file keystore in the information area. The password is the password used to generate the signature file.

  4. Obtain the SHA-256 fingerprint from the result. Save for next step.

Add fingerprint certificate to AppGallery Connect

During this step, you will configure the generated SHA-256 fingerprint in AppGallery Connect.

  1. In AppGallery Connect, click the app that you have created and go to Develop> Overview
  2. Go to the App information section and enter the SHA-256 fingerprint that you generated earlier.
  3. Click √ to save the fingerprint.

2 - Import the plugin to your Unity Project

To import the plugin:

  1. Download the .unitypackage
  2. Open your game in Unity
  3. Choose Assets> Import Package> Custom Import Package
  4. In the file explorer select the downloaded HMS Unity plugin. The Import Unity Package dialog box will appear, with all the items in the package pre-checked, ready to install. image
  5. Select Import and Unity will deploy the Unity plugin into your Assets Folder

3 - Update your agconnect-services.json file.

In order for the plugin to work, some kits are in need of agconnect-json file. Please download your latest config file from AGC and import into Assets/StreamingAssets folder. image


4 - Connect your game with any HMS Kit

In order for the plugin to work, you need to select the needed kits Huawei > Kit Settings.

image

It will automaticly create the GameObject for you and it has DontDestroyOnLoad implemented so you don't need to worry about reference being lost.

Now you need your game to call the Kit Managers from your game. See below for further instructions.

Account Kit (Sign In)

Call login method in order to open the login dialog. Be sure to have AccountKit enabled in Huawei > Kit Settings.

HMSAccountManager.Instance.SignIn();
Analytics kit
  1. Enable Analtics kit from AGC
  2. Update ...Assets\StreamingAssets\agconnect-services.json file

Send analytics function:

HMSAnalyticsManager.Instance.SendEventWithBundle(eventId, key, value);
In App Purchases

Register your products via custom editor under Huawei > Kit Settings > IAP tab. image Write your product identifier that is in AGC and select product type.

If you check "Initialize On Start" checkbox, it'll automaticly retrieve registered products on Start. If you want to initialize the IAP by yourself, call the function mentioned in below. You can also set callbacks as well.

HMSIAPManager.Instance.CheckIapAvailability();

HMSIAPManager.Instance.OnCheckIapAvailabilitySuccess += OnCheckIapAvailabilitySuccess;
HMSIAPManager.Instance.OnCheckIapAvailabilityFailure += OnCheckIapAvailabilityFailure;

private void OnCheckIapAvailabilityFailure(HMSException obj)
    {
        
    }

    private void OnCheckIapAvailabilitySuccess()
    {
        
    }

Open the Purchase dialog by calling to BuyProduct method. You can set callbacks and check which product was purchased.

HMSIAPManager.Instance.BuyProduct(string productID)

HMSIAPManager.Instance.OnBuyProductSuccess += OnBuyProductSuccess;

private void OnBuyProductSuccess(PurchaseResultInfo obj)
    {
        if(obj.InAppPurchaseData.ProductId == "removeAds")
        {
            // Write your remove ads logic here.
        }
    }

Restore purchases that have been bought by user before.

 HMSIAPManager.Instance.RestorePurchases((restoredProducts) =>
        {
            //restoredProducts contains all products that has been restored.
        });

You can also use "Create Constant Classes" button to create a class called HMSIAPConstants which will contain all products as constants and you can call it from your code. Such as;

HMSIAPManager.Instance.BuyProduct(HMSIAPConstants.testProduct);
Ads kit

There is a custom editor in Huawei > Kit Settings > Ads tab. image

You can enable/disable ads that you want in your project. Insert your Ad Id into these textboxes in the editor. If you want to use test ads, you can check UseTestAds checkbox that'll overwrite all ad ids with test ads.

Then you can call certain functions such as

    HMSAdsKitManager.Instance.ShowBannerAd();
    HMSAdsKitManager.Instance.HideBannerAd();
    HMSAdsKitManager.Instance.ShowInterstitialAd();
    
    HMSAdsKitManager.Instance.OnRewarded = OnRewarded;
    HMSAdsKitManager.Instance.ShowRewardedAd();
    
    public void OnRewarded(Reward reward)
    {
       
    }
Game kit

There is a custom editor in Huawei > Kit Settings > Game Service tab. image

You can also use "Create Constant Classes" button to create a class called HMSLeaderboardConstants or HMSAchievementConstants which will contain all achievements and leaderboards as constants and you can call it from your code. Such as;

    HMSLeaderboardManager.Instance.ReportScore(HMSLeaderboardConstants.topleaderboard,50);
    HMSAchievementsManager.Instance.RevealAchievement(HMSAchievementConstants.firstshot);

You can call native calls to list achievements or leaderboards.

  HMSAchievementsManager.Instance.ShowAchievements();
  HMSLeaderboardManager.Instance.ShowLeaderboards();

Kits Specification

Find below the specific information on the included functionalities in this plugin

  1. Account
  2. In App Purchases
  3. Ads
  4. Push notifications
  5. Game
  6. Analytics
  7. Remote Config
  8. Crash
  9. Cloud DB

Account

Official Documentation on Account Kit: Documentation

In App Purchases

Official Documentation on IAP Kit: Documentation

Ads

Official Documentation on Ads Kit: Documentation

Push

Official Documentation on Push Kit: Documentation

Game

Official Documentation on Game Kit: Documentation

Analytics

Official Documentation on Analytics Kit: Documentation

Remote Config

Official Documentation on Analytics Kit: Documentation

Crash

Official Documentation on Analytics Kit: Documentation

Cloud DB

Official Documentation on Analytics Kit: Documentation


License

This project is licensed under the MIT License


Troubleshoot

***unamgious unity file change issue fix suggestion *** If you change content of codes or files related with unity project and face an unambigious issue: 1. Save your existing unity project 2. Backup existing meta files of unity files that you have a problem on 3. Delete existing (.meta) metafile of it and try re-building your unity project


License

This project is licensed under the MIT License

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published