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 bool PlayInterstitial(TKGIVAdPositionName pAdPos , bool pNormalIV = true, Action pCallback = null) { if (PlayerData.Instance.IsNoAds) { pCallback?.Invoke(); return false; } if (PlayerData.Instance.LoginCount == 1 && PlayerData.Instance.CurrentLevel <= TKGSDKManager.Instance.GetConfigInt(TKGParamKey.LevelInterSwitch)) { pCallback?.Invoke(); return false; } bool tHasShowedNoAds = false; #if USE_IAP if (TKGUtils.WillPlayInterstitial(pNormalIV) && 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, pNormalIV ? Touka.IVADType.IV1 : Touka.IVADType.IV2); } else { pCallback?.Invoke(); } }; tHasShowedNoAds = true; } else { Debug.Log("show interstitial when doesn't reach delta"); TKGSDKManager.Instance.PlayInterstitialAd(pAdPos, pCallback, pNormalIV ? Touka.IVADType.IV1 : Touka.IVADType.IV2); } sInterstitialShowCount++; } else { Debug.Log("show interstitial normally"); TKGSDKManager.Instance.PlayInterstitialAd(pAdPos, pCallback, pNormalIV ? Touka.IVADType.IV1 : Touka.IVADType.IV2); } #else TKGSDKManager.Instance.ShowInterstitialAd(pAdPos, pCallback, pNormalIV ? Touka.IVADType.IV1 : Touka.IVADType.IV2); #endif return tHasShowedNoAds; } public static void PlayReward(TKGRVPositionName pAdPos, Action pSuccessCallback = null) { TKGSDKManager.Instance.ShowRewardAd(pAdPos, (pResult) => { pSuccessCallback?.Invoke(); }, noUnityTips, true); } private static void noUnityTips() { } }