mergemilitary/Assets/Scripts/Utils/AdsUtils.cs

86 lines
2.8 KiB
C#
Raw Normal View History

2022-05-23 13:39:59 +00:00
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)
2022-05-23 13:39:59 +00:00
{
if (PlayerData.Instance.IsNoAds)
{
pCallback?.Invoke();
2022-06-08 13:23:44 +00:00
return false;
2022-05-23 13:39:59 +00:00
}
if (PlayerData.Instance.LoginCount == 1 && PlayerData.Instance.CurrentLevel <= TKGSDKManager.Instance.GetConfigInt(TKGParamKey.LevelInterSwitch))
2022-05-23 13:39:59 +00:00
{
pCallback?.Invoke();
2022-06-08 13:23:44 +00:00
return false;
2022-05-23 13:39:59 +00:00
}
2022-06-08 13:23:44 +00:00
bool tHasShowedNoAds = false;
2022-05-30 09:31:03 +00:00
#if USE_IAP
2022-06-08 13:23:44 +00:00
if (TKGUtils.WillPlayInterstitial(pNormalIV) && sNoAdsShowCount < SHOW_NOADS_MAX_COUNT)
2022-05-23 13:39:59 +00:00
{
if ((sInterstitialShowCount > TKGSDKManager.Instance.GetConfigInt(TKGParamKey.RemoveAdsShow.ToString())) && (sInterstitialShowCount % TKGSDKManager.Instance.GetConfigInt(TKGParamKey.RemoveAds.ToString()) == 0))
{
sNoAdsShowCount++;
PanelBuyNoAds tUIBuy = UIManager.Instance.OpenUI<PanelBuyNoAds>();
tUIBuy.DelResult = (pResult) =>
{
if (!pResult)
{
Debug.Log("show interstitial after show buy no ads");
2022-06-08 13:23:44 +00:00
TKGSDKManager.Instance.PlayInterstitialAd(pAdPos, pCallback, pNormalIV ? Touka.IVADType.IV1 : Touka.IVADType.IV2);
2022-05-23 13:39:59 +00:00
}
else
{
pCallback?.Invoke();
}
};
2022-06-08 13:23:44 +00:00
tHasShowedNoAds = true;
2022-05-23 13:39:59 +00:00
}
else
{
Debug.Log("show interstitial when doesn't reach delta");
2022-06-08 13:23:44 +00:00
TKGSDKManager.Instance.PlayInterstitialAd(pAdPos, pCallback, pNormalIV ? Touka.IVADType.IV1 : Touka.IVADType.IV2);
2022-05-23 13:39:59 +00:00
}
sInterstitialShowCount++;
}
else
{
Debug.Log("show interstitial normally");
2022-06-08 13:23:44 +00:00
TKGSDKManager.Instance.PlayInterstitialAd(pAdPos, pCallback, pNormalIV ? Touka.IVADType.IV1 : Touka.IVADType.IV2);
2022-05-23 13:39:59 +00:00
}
2022-05-30 09:31:03 +00:00
#else
TKGSDKManager.Instance.ShowInterstitialAd(pAdPos, pCallback, pNormalIV ? Touka.IVADType.IV1 : Touka.IVADType.IV2);
2022-05-30 09:31:03 +00:00
#endif
2022-06-08 13:23:44 +00:00
return tHasShowedNoAds;
2022-05-23 13:39:59 +00:00
}
public static void PlayReward(TKGRVPositionName pAdPos, Action pSuccessCallback = null)
2022-05-23 13:39:59 +00:00
{
TKGSDKManager.Instance.ShowRewardAd(pAdPos, (pResult) =>
2022-05-23 13:39:59 +00:00
{
2022-08-31 13:09:23 +00:00
if (pResult)
{
pSuccessCallback?.Invoke();
}
}, noUnityTips, true);
2022-05-23 13:39:59 +00:00
}
private static void noUnityTips()
{
}
2022-05-23 13:39:59 +00:00
}