mergemilitary/Assets/Scripts/Utils/AdsUtils.cs

81 lines
2.9 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;
2022-06-08 13:23:44 +00:00
public static bool PlayInterstitial(string 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.ToString()))
{
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-07-04 11:17:39 +00:00
if (TKGSDKManager.Instance.IsIAPEnabled)
2022-05-23 13:39:59 +00:00
{
2022-07-04 11:17:39 +00:00
if (TKGUtils.WillPlayInterstitial(pNormalIV) && sNoAdsShowCount < SHOW_NOADS_MAX_COUNT)
2022-05-23 13:39:59 +00:00
{
2022-07-04 11:17:39 +00:00
if ((sInterstitialShowCount > TKGSDKManager.Instance.GetConfigInt(TKGParamKey.RemoveAdsShow.ToString())) && (sInterstitialShowCount % TKGSDKManager.Instance.GetConfigInt(TKGParamKey.RemoveAds.ToString()) == 0))
2022-05-23 13:39:59 +00:00
{
2022-07-04 11:17:39 +00:00
sNoAdsShowCount++;
PanelBuyNoAds tUIBuy = UIManager.Instance.OpenUI<PanelBuyNoAds>();
tUIBuy.DelResult = (pResult) =>
2022-05-23 13:39:59 +00:00
{
2022-07-04 11:17:39 +00:00
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();
}
};
2022-06-08 13:23:44 +00:00
2022-07-04 11:17:39 +00:00
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++;
2022-05-23 13:39:59 +00:00
}
else
{
2022-07-04 11:17:39 +00:00
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
}
}
else
{
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-06-08 13:23:44 +00:00
return tHasShowedNoAds;
2022-05-23 13:39:59 +00:00
}
public static void PlayReward(string pAdPos = "", Action pSuccessCallback = null)
{
TKGSDKManager.Instance.PlayRewardAd(pAdPos, (pResult) =>
{
pSuccessCallback?.Invoke();
2022-07-04 11:17:39 +00:00
MMOModule.Instance.WatchAdSuccessfully();
2022-05-23 13:39:59 +00:00
}, UIUtils.ShowNoAdsTip);
}
}