Giter Site home page Giter Site logo

popballoons-hmsunityplugin-referencegame's Introduction

PopBalloons-hmsUnityPlugin-ReferenceGame

Welcome to Balloon Popping! A fun and challenging game that tests your balloon popping skills! The goal of the game is to pop as many balloons as possible before they reach the top of the screen. Each time you pop a blue, green, or pink balloon, you will earn points. But be careful, if you pop a black balloon, you will lose.

image

image

The game also features in-app purchases and ads, allowing you to enhance your experience and support the development of the game.

The game uses the HMS in-app purchase kit and Ads kit to show a demo of it to how to use.

Please enjoy and have fun playing Balloon Popping!

In this project, we explain the use of Unity Plugin of Huawei Mobile Services on this game.

Huawei Mobile Services Plugin

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

Requirements

Quick Start

Account Kit

Purpose In Project : Sign in automatically.

Use In Project : By calling this method HMSAccountKitManager.Instance.SignIn(); at AccountManager.cs 45

 

 void Start()
 {
     HMSAccountKitManager.Instance.OnSignInSuccess = OnLoginSuccess;
     HMSAccountKitManager.Instance.OnSignInFailed = OnLoginFailure;

     AccountKitLog?.Invoke(NOT_LOGGED_IN);

 }

IAP

Purpose In Project : Selling the product of "Remove Ads".

Use In Project :

  1. By clicking "No Ads" button in game menu.This button calls this method has on clicker at StoreManager.cs 204
 #region ButtonClick: BuyProduct

 product.transform.GetChild(4).gameObject.GetComponent<Button>().onClick.AddListener(delegate { BuyProduct(productInfo.ProductId); });
 
 #endregion
  1. BuyProduct(productInfo.ProductId); command invokes OnBuyProduct(string productID) at StoreManager.cs 33
    #region Events: OnBuyProduct

    private void OnBuyProduct(string productID)
    {
        HMSIAPManager.Instance.BuyProduct(productID);
    }

    #endregion
  1. If purchase request return success for all products callback method will be called automatically.In this method we handle the having "No Ads", "Booster" and "Pink Color" item. No Ads represents Subscription product. Booster represents Consumable product and PinkColor represents NonConsumable product of IAP.
 #region Events: BuyProductSuccess

  private void OnBuyProductSuccess(PurchaseResultInfo obj)
 {
     Debug.Log("OnBuyProductSuccess:" + obj.InAppPurchaseData.ProductName);

     if (obj.InAppPurchaseData.ProductId == HMSIAPConstants.NoAds)
     {
         AdsManager adsManager = gameObject.AddComponent<AdsManager>();
         adsManager.DisableAds();
         Debug.Log("NOADS HAS PURCHASED");
         
         
     }
     else if (obj.InAppPurchaseData.ProductId == HMSIAPConstants.Booster)
     {
         int currentBoosterCount = PlayerPrefs.GetInt("booster_count", 0);
         currentBoosterCount++;
         PlayerPrefs.SetInt("booster_count", currentBoosterCount);
         PlayerPrefs.Save();
         Debug.Log("BOOSTER HAS PURCHASED");

         UIController uIController = FindObjectOfType<UIController>();
         uIController.DisplayBoosterCount();

     }
     else if (obj.InAppPurchaseData.ProductId == HMSIAPConstants.PinkColor)
     {
         BalloonColor balloonColor = new BalloonColor();
         balloonColor.UnlockColor();
         Debug.Log("PINK COLOR HAS PURCHASED");
     }
    
 }

 #endregion

Ads Kit

Purpose In Project : Monetizing with Interstial Ads, Banner Ads, Native Ads and Splash Ads.

Use In Project :

  1. Banner Ads and Interstitial Ads : By calling this method ShowBanner() at AdsManager.cs 69 and HMSAdsKitManager.Instance.ShowInterstitialAd(); at AdsManager.cs 72.We are calling these methods at first,a nd you can hide banner ads by calling HideBanner() at AdsManager.cs 61.
  public void ShowAds()
 {
     
         HMSAdsKitManager.Instance.ShowBannerAd();
         if (HMSAdsKitManager.Instance.IsInterstitialAdLoaded)
         {
             HMSAdsKitManager.Instance.ShowInterstitialAd();
         }

         rewardedAdPanel.SetActive(true);

    
     
 }
  1. Rewarded Ads : By calling this method invoking events using HMSAdsKitManager.Instance.OnRewardedAdLoaded at AdsManager.cs 35 and 36
  
  HMSAdsKitManager.Instance.OnRewardedAdLoaded = OnRewardedAdLoaded;
  HMSAdsKitManager.Instance.OnRewardAdCompleted = OnRewardAdCompleted;

We give awards when the ads completed on OnRewardAdCompleted() method at AdsManager.cs 96.

    private void OnRewardAdCompleted()
    {
        Debug.Log("ON REWARD COMPLETED!");
        rewardedAdPanel.SetActive(false);
        TotalScore totalScore = FindObjectOfType<TotalScore>();
        totalScore.DoubleScore();

        didRewardedEarned = true;
    }
  1. NativeAds : NativeAds being handled at the NativeAd prefab. At LargeImageNative.cs on line 29 LoadNativeAd() method calls for native ad.
     void Start()
    {
        why_this_ad.onClick.AddListener(delegate { GotoWhyThisAdPage(); });
        LoadNativeAd();
    }

In App Comment

Purpose In Project : Providing users to submit ratings and make comments for app without leaving the application.

Use In Project : Its called in Start() function at UIController.cs 14.

    

   private void Start()
    {
        Debug.Log("ShowInAppComment");
        InAppComment.ShowInAppComment();
        
        gameCanvas.SetActive(true);
        gameOverCanvas.SetActive(false);
        storeCanvas.SetActive(false);

        
    }

popballoons-hmsunityplugin-referencegame's People

Contributors

andronovo-bit avatar bunyamineymen avatar htpck avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.