mergemilitary/Assets/Scripts/Utils/AdsUtils.cs

112 lines
3.6 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-09-09 14:35:49 +00:00
public static bool PlayInterstitial(TKGIVAdPositionName pAdPos, bool pIsWin = 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
}
2022-09-09 14:35:49 +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-09-09 14:35:49 +00:00
Touka.IVADType tIVType = pIsWin ? Touka.IVADType.IV1 : Touka.IVADType.IV2;
2022-07-04 11:17:39 +00:00
if (TKGSDKManager.Instance.IsIAPEnabled)
2022-05-23 13:39:59 +00:00
{
2022-09-09 14:35:49 +00:00
if (TKGSDKManager.Instance.IsReadyInterstitialAd() && sNoAdsShowCount < SHOW_NOADS_MAX_COUNT)
2022-05-23 13:39:59 +00:00
{
2022-09-09 14:35:49 +00:00
if ((sInterstitialShowCount > TKGSDKManager.Instance.GetConfigInt(TKGParamKey.RemoveAdsShow)) && (sInterstitialShowCount % TKGSDKManager.Instance.GetConfigInt(TKGParamKey.RemoveAds) == 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");
2022-09-09 14:35:49 +00:00
TKGSDKManager.Instance.ShowInterstitialAd(pAdPos, pCallback, tIVType);
2022-07-04 11:17:39 +00:00
}
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");
2022-09-09 14:35:49 +00:00
TKGSDKManager.Instance.ShowInterstitialAd(pAdPos, pCallback, tIVType);
2022-07-04 11:17:39 +00:00
}
sInterstitialShowCount++;
2022-05-23 13:39:59 +00:00
}
else
{
2022-07-04 11:17:39 +00:00
Debug.Log("show interstitial normally");
2022-09-09 14:35:49 +00:00
TKGSDKManager.Instance.ShowInterstitialAd(pAdPos, pCallback, tIVType);
2022-05-23 13:39:59 +00:00
}
}
else
{
2022-09-09 14:35:49 +00:00
Debug.Log("show interstitial normally");
TKGSDKManager.Instance.ShowInterstitialAd(pAdPos, pCallback, tIVType);
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
}
2022-09-09 14:35:49 +00:00
public static void PlayReward(TKGRVPositionName pAdPos, Action pSuccessCallback = null)
2022-05-23 13:39:59 +00:00
{
2022-09-09 14:35:49 +00:00
if (TKGSDKManager.Instance.IsReadyRewardAd())
2022-05-23 13:39:59 +00:00
{
2022-09-09 14:35:49 +00:00
TKGSDKManager.Instance.ShowRewardAd(pAdPos, (pResult) =>
2022-08-11 03:33:10 +00:00
{
2022-09-09 14:35:49 +00:00
if (pResult)
{
pSuccessCallback?.Invoke();
MMOModule.Instance.WatchRVSuccessfully();
}
}, UIUtils.ShowNoAdsTip);
}
else
{
UIUtils.ShowNoAdsTip();
}
}
public static void PlayReward(TKGRVPositionName pAdPos, Action<bool> pResultCallback = null)
{
if (TKGSDKManager.Instance.IsReadyRewardAd())
{
TKGSDKManager.Instance.ShowRewardAd(pAdPos, (pResult) =>
{
pResultCallback?.Invoke(pResult);
if (pResult)
{
MMOModule.Instance.WatchRVSuccessfully();
}
}, UIUtils.ShowNoAdsTip);
}
else
{
UIUtils.ShowNoAdsTip();
}
2022-05-23 13:39:59 +00:00
}
}