Unity Reference Game Application with GMS + HMS integration(Unity+HMS+GMS)
Hyper-casual / agility game
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
- Google Sign-In Unity Plugin
- Firebase Cloud Messaging
- Google Admob
- Firebase Analytics
- Firebase Crashlytics
- Firebase Remoteconfig
-
Helper links for creating and configuring unity based firebase project:
-
UPM Method chosen to import Firabase services
( Firebase app(core),
Firebase authentication,
Firebase cloud messaging,
Firebase Crashlytics,
Firebase remote config,
Google Analytics for Firebase) to your unity project on unity editor which can be seen on following link:
https://laptrinhx.com/managing-the-firebase-unity-plugin-the-easy-way-1600281350/
-
Google Sign-In Unity Plugin
-
Firebase Cloud Messaging
https://firebase.google.com/docs/cloud-messaging/unity/client
-
Google Admob
-
Firebase Analytics
-
Firebase Crashlytics
https://firebase.google.com/docs/crashlytics/get-started?platform=unity
-
Firebase Remoteconfig
https://firebase.google.com/docs/remote-config/use-config-unity
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
Android SDK min 21 Net 4.x
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
Please check our wiki page
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.
- Native Ads Integration
- Register your app at Huawei Developer
- Import the Plugin to your Unity project
- Connect your game with the HMS Kit Managers
1.1- Register at Huawei Developer
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.
- Sign in to Huawei Developer and click Console.
- Click the HUAWEI AppGallery card and access AppGallery Connect.
- On the AppGallery Connect page, click My apps.
- On the displayed My apps page, click New.
- Enter the App name, select App category (Game), and select Default language as needed.
- 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.
Set the package name of the created application on the AGC.
- 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.
- 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
Create a keystore using Unity or Android Tools. make sure your Unity project uses this keystore under the Build Settings>PlayerSettings>Publishing settings
During this step, you will need to export the SHA-256 fingerprint by using keytool provided by the JDK and signature file.
-
Open the command window or terminal and access the bin directory where the JDK is installed.
-
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
-
Enter the password of the signature file keystore in the information area. The password is the password used to generate the signature file.
-
Obtain the SHA-256 fingerprint from the result. Save for next step.
During this step, you will configure the generated SHA-256 fingerprint in AppGallery Connect.
- In AppGallery Connect, click the app that you have created and go to Develop> Overview
- Go to the App information section and enter the SHA-256 fingerprint that you generated earlier.
- Click √ to save the fingerprint.
To import the plugin:
- Download the .unitypackage
- Open your game in Unity
- Choose Assets> Import Package> Custom
- 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.
- Select Import and Unity will deploy the Unity plugin into your Assets Folder
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.
In order for the plugin to work, you need to select the needed kits Huawei > Kit Settings.
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.
Call login method in order to open the login dialog. Be sure to have AccountKit enabled in Huawei > Kit Settings.
HMSAccountManager.Instance.SignIn();
- Enable Analtics kit from AGC
- Update ...Assets\StreamingAssets\agconnect-services.json file
Send analytics function:
HMSAnalyticsManager.Instance.SendEventWithBundle(eventId, key, value);
Register your products via custom editor under Huawei > Kit Settings > IAP tab. 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);
There is a custom editor in Huawei > Kit Settings > Ads tab.
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)
{
}
There is a custom editor in Huawei > Kit Settings > Game Service tab.
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();
Find below the specific information on the included functionalities in this plugin
- Account
- In App Purchases
- Ads
- Push notifications
- Game
- Analytics
- Remote Config
- Crash
- Cloud DB
Official Documentation on Account Kit: Documentation
Official Documentation on IAP Kit: Documentation
Official Documentation on Ads Kit: Documentation
Official Documentation on Push Kit: Documentation
Official Documentation on Game Kit: Documentation
Official Documentation on Analytics Kit: Documentation
Official Documentation on Analytics Kit: Documentation
Official Documentation on Analytics Kit: Documentation
Official Documentation on Analytics Kit: Documentation
This project is licensed under the MIT License
***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
This project is licensed under the MIT License