using System; using System.Collections.Generic; using UnityEngine; public static class AdsUtils { private static int sInterstitialShowCount = 0; private static int sNoAdsShowCount = 0; private const int SHOW_NOADS_MAX_COUNT = 3; public static void PlayInterstitial(string pAdPos = "", Action pCallback = null) { if (PlayerData.Instance.IsNoAds) { pCallback?.Invoke(); return; } if (PlayerData.Instance.LoginCount == 1 && PlayerData.Instance.CurrentLevel <= TKGSDKManager.Instance.GetConfigInt(TKGParamKey.LevelInterSwitch.ToString())) { pCallback?.Invoke(); return; } #if USE_IAP if (TKGUtils.WillPlayInterstitial() && sNoAdsShowCount < SHOW_NOADS_MAX_COUNT) { if ((sInterstitialShowCount > TKGSDKManager.Instance.GetConfigInt(TKGParamKey.RemoveAdsShow.ToString())) && (sInterstitialShowCount % TKGSDKManager.Instance.GetConfigInt(TKGParamKey.RemoveAds.ToString()) == 0)) { sNoAdsShowCount++; PanelBuyNoAds tUIBuy = UIManager.Instance.OpenUI(); tUIBuy.DelResult = (pResult) => { if (!pResult) { Debug.Log("show interstitial after show buy no ads"); TKGSDKManager.Instance.PlayInterstitialAd(pAdPos, pCallback); } else { pCallback?.Invoke(); } }; } else { Debug.Log("show interstitial when doesn't reach delta"); TKGSDKManager.Instance.PlayInterstitialAd(pAdPos, pCallback); } sInterstitialShowCount++; } else { Debug.Log("show interstitial normally"); TKGSDKManager.Instance.PlayInterstitialAd(pAdPos, pCallback); } #else TKGSDKManager.Instance.PlayInterstitialAd(pAdPos, pCallback); #endif } public static void PlayReward(string pAdPos = "", Action pSuccessCallback = null) { TKGSDKManager.Instance.PlayRewardAd(pAdPos, (pResult) => { pSuccessCallback?.Invoke(); }, UIUtils.ShowNoAdsTip); } }