mergemilitary/Assets/Scripts/Utils/AdsUtils.cs

98 lines
3.3 KiB
C#

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 pIsWin = 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;
Touka.IVADType tIVType = pIsWin ? Touka.IVADType.IV1 : Touka.IVADType.IV2;
if (TKGSDKManager.Instance.IsIAPEnabled)
{
if (TKGSDKManager.Instance.IsReadyInterstitialAd() && sNoAdsShowCount < SHOW_NOADS_MAX_COUNT)
{
if ((sInterstitialShowCount > TKGSDKManager.Instance.GetConfigInt(TKGParamKey.RemoveAdsShow)) && (sInterstitialShowCount % TKGSDKManager.Instance.GetConfigInt(TKGParamKey.RemoveAds) == 0))
{
sNoAdsShowCount++;
PanelBuyNoAds tUIBuy = UIManager.Instance.OpenUI<PanelBuyNoAds>();
tUIBuy.DelResult = (pResult) =>
{
if (!pResult)
{
Debug.Log("show interstitial after show buy no ads");
TKGSDKManager.Instance.ShowInterstitialAd(pAdPos, pCallback, tIVType);
}
else
{
pCallback?.Invoke();
}
};
tHasShowedNoAds = true;
}
else
{
Debug.Log("show interstitial when doesn't reach delta");
TKGSDKManager.Instance.ShowInterstitialAd(pAdPos, pCallback, tIVType);
}
sInterstitialShowCount++;
}
else
{
Debug.Log("show interstitial normally");
TKGSDKManager.Instance.ShowInterstitialAd(pAdPos, pCallback, tIVType);
}
}
else
{
Debug.Log("show interstitial normally");
TKGSDKManager.Instance.ShowInterstitialAd(pAdPos, pCallback, tIVType);
}
return tHasShowedNoAds;
}
public static void PlayReward(TKGRVPositionName pAdPos, Action pSuccessCallback = null)
{
TKGSDKManager.Instance.ShowRewardAd(pAdPos, (pResult) =>
{
if (pResult)
{
pSuccessCallback?.Invoke();
MMOModule.Instance.WatchRVSuccessfully();
}
}, null, true);
}
public static void PlayReward(TKGRVPositionName pAdPos, Action<bool> pResultCallback = null)
{
TKGSDKManager.Instance.ShowRewardAd(pAdPos, (pResult) =>
{
pResultCallback?.Invoke(pResult);
if (pResult)
{
MMOModule.Instance.WatchRVSuccessfully();
}
}, null, true);
}
}