diff --git a/Assets/Huawei/Demos/Ads/AdsDemoManager.cs b/Assets/Huawei/Demos/Ads/AdsDemoManager.cs index 48bc7fed..4412c279 100644 --- a/Assets/Huawei/Demos/Ads/AdsDemoManager.cs +++ b/Assets/Huawei/Demos/Ads/AdsDemoManager.cs @@ -32,16 +32,17 @@ private void Awake() private void Start() { - HMSAdsKitManager.Instance.OnRewarded = OnRewarded; - HMSAdsKitManager.Instance.OnInterstitialAdClosed = OnInterstitialAdClosed; - - HMSAdsKitManager.Instance.ConsentOnFail = OnConsentFail; - HMSAdsKitManager.Instance.ConsentOnSuccess = OnConsentSuccess; + HMSAdsKitManager.Instance = new HMSAdsKitManager(hasPurchasedNoAds: false) + { + OnRewarded = OnRewarded, + OnInterstitialAdClosed = OnInterstitialAdClosed, + ConsentOnFail = OnConsentFail, + ConsentOnSuccess = OnConsentSuccess + }; HMSAdsKitManager.Instance.RequestConsentUpdate(); //testAdStatusToggle = GameObject.FindGameObjectWithTag("Toggle").GetComponent(); //testAdStatusToggle.isOn = HMSAdsKitSettings.Instance.Settings.GetBool(HMSAdsKitSettings.UseTestAds); - #region SetNonPersonalizedAd , SetRequestLocation @@ -59,7 +60,6 @@ private void Start() Debug.Log($"{TAG}Consent: {requestOptions.Consent}"); #endregion - } private void OnConsentSuccess(ConsentStatus consentStatus, bool isNeedConsent, IList adProviders) diff --git a/Assets/Huawei/Scripts/Ads/HMSAdsKitManager.cs b/Assets/Huawei/Scripts/Ads/HMSAdsKitManager.cs index 7f9bc9de..0bc18305 100644 --- a/Assets/Huawei/Scripts/Ads/HMSAdsKitManager.cs +++ b/Assets/Huawei/Scripts/Ads/HMSAdsKitManager.cs @@ -1,14 +1,11 @@ using HuaweiConstants; - using HuaweiMobileServices.Ads; using HuaweiMobileServices.Ads.InstallReferrer; using HuaweiMobileServices.Utils; using System; using System.Collections.Generic; using System.Threading.Tasks; - using UnityEngine; - using static HuaweiConstants.UnityBannerAdPositionCode; using static HuaweiMobileServices.Ads.SplashAd; @@ -34,11 +31,13 @@ public class HMSAdsKitManager : HMSManagerSingleton private bool isInitialized; + private InstallReferrerClient installReferrerClient; + public Action InstallReferrerSuccess { get; set; } public Action InstallReferrerFail { get; set; } public Action InstallReferrerDisconnect { get; set; } - InstallReferrerClient installReferrerClient; + public bool hasPurchasedNoAds = false; public HMSAdsKitManager() { @@ -46,12 +45,17 @@ public HMSAdsKitManager() HMSManagerStart.Start(OnAwake, OnStart, TAG); } + public HMSAdsKitManager(bool hasPurchasedNoAds) + { + adsKitSettings = HMSAdsKitSettings.Instance.Settings; + this.hasPurchasedNoAds = hasPurchasedNoAds; + HMSManagerStart.Start(OnAwake, () => { OnStart(hasPurchasedNoAds);}, TAG); + } + private void OnAwake() { Debug.Log($"{TAG} OnAwake"); Init(); - if (adsKitSettings.GetBool(HMSAdsKitSettings.EnableSplashAd)) - LoadSplashAd(); } private void OnStart() @@ -60,6 +64,12 @@ private void OnStart() LoadAdsWhenInternetIsAvailable(); } + private void OnStart(bool hasPurchasedNoAds = false) + { + Debug.Log($"{TAG} OnStart"); + LoadAdsWhenInternetIsAvailable(hasPurchasedNoAds); + } + private void Init() { Debug.Log($"{TAG} Init"); @@ -68,19 +78,21 @@ private void Init() adsKitSettings = HMSAdsKitSettings.Instance.Settings; } - private async void LoadAdsWhenInternetIsAvailable() + private async void LoadAdsWhenInternetIsAvailable(bool hasPurchasedNoAds = false) { while (Application.internetReachability == NetworkReachability.NotReachable) await Task.Delay(TimeSpan.FromSeconds(0.5)); Debug.Log($"{TAG} Loading Ads"); - LoadAllAds(); + LoadAllAds(hasPurchasedNoAds); } public void LoadAllAds(bool hasPurchasedNoAds = false) { if (!hasPurchasedNoAds) { + if (adsKitSettings.GetBool(HMSAdsKitSettings.EnableSplashAd)) + LoadSplashAd(); UnityBannerAdPositionCodeType _adPositionCodeType = UnityBannerAdPositionCodeType.POSITION_BOTTOM; UnityBannerAdSizeType _adSizeType = UnityBannerAdSizeType.BANNER_SIZE_360_57; diff --git a/Assets/Huawei/Scripts/Utils/HMSSingleton.cs b/Assets/Huawei/Scripts/Utils/HMSSingleton.cs index 67682086..e6d1da36 100644 --- a/Assets/Huawei/Scripts/Utils/HMSSingleton.cs +++ b/Assets/Huawei/Scripts/Utils/HMSSingleton.cs @@ -42,9 +42,10 @@ public static T Instance } } } + public class HMSManagerSingleton where T : new() { - private static readonly Lazy _instance = new Lazy(() => new T()); + private static Lazy _instance = new Lazy(() => new T()); public static T Instance { @@ -52,5 +53,6 @@ public static T Instance { return _instance.Value; } + set => _instance = new Lazy(() => value); } } \ No newline at end of file