Professional Documents
Culture Documents
Main Player Json File Fomat
Main Player Json File Fomat
Main Player Json File Fomat
using UnityEngine;
using GoogleMobileAds.Api;
using GoogleMobileAds.Common;
[SerializeField]
bool showAppOpenAd, StopShowingAdsOnLowEndDevices;
[SerializeField]
string[] admobBannerIds;
[SerializeField]
string[] admobInterstitialIds;
[SerializeField]
string admobRewardedInterstitialID, admobRewardedVideoID, appOpenAdID;
[SerializeField]
bool ShowTestAds;
int minRamSize;
bool isAdAlreadyShowing;
float deviceRam;
void Awake()
{
if (instance != this && instance != null)
{
Destroy(gameObject);
}
else
{
instance = this;
}
DontDestroyOnLoad(gameObject);
AppStateEventNotifier.AppStateChanged += OnAppStateChanged;
}
void onInitializationComp()
{
Invoke("LoadVideoAD", 5f);
tryToLoadAllInterstitials();
Invoke("loadAdmobRewardedInterstitial", 6f);
if (showAppOpenAd)
LoadAppOpenAd();
UnityEngine.SceneManagement.SceneManager.LoadScene(UnityEngine.SceneMa
nagement.SceneManager.GetActiveScene().buildIndex + 1);
}
void checkForAdIds()
{
if (admobBannerIds.Length > 0)
{
if (admobBannerIds[0] == "")
admobBannerIds[0] = "ca-app-pub-3940256099942544/6300978111";
}
for (int i = 0; i < admobInterstitialIds.Length; i++)
{
if (admobInterstitialIds[i] == "" || admobInterstitialIds[i] ==
null)
admobInterstitialIds[i] = "ca-app-pub-
3940256099942544/1033173712";
}
#region Banners
int bannerInc = 0;
AdRequest CreateAdRequest()
{
var adRequest = new AdRequest.Builder().Build();
//adRequest.Keywords.Add("unity-admob-sample");
return adRequest;
}
BannerView showAdmobBanner(BannerView view, AdSize size, AdPosition
position)
{
if (StopShowingAdsOnLowEndDevices && deviceRam < minRamSize)
return null;
if (view != null)
{
view.Destroy();
view = null;
}
bannerInc++;
if (bannerInc >= admobBannerIds.Length)
bannerInc = 0;
}
view = new BannerView(banId, size, position);
view.LoadAd(CreateAdRequest());
ListenToAdEvents(view);
return view;
}
_view.OnBannerAdLoaded += () =>
{
changeBannerBools(_view, true);
};
if (view != null)
view.Hide();
}
if (!bannerViewTopLoaded)
{
bannerViewTop = showAdmobBanner(bannerViewTop, AdSize.Banner,
AdPosition.Top);
}
else
{
if (bannerViewTop != null)
{
bannerViewTop.Show();
bannerViewTopShowing = true;
}
}
}
public void showAdMobBannerBottom()
{
if (StopShowingAdsOnLowEndDevices && deviceRam < minRamSize)
return;
if (!bannerViewBottomLoaded)
{
bannerViewBottom = showAdmobBanner(bannerViewBottom,
AdSize.Banner, AdPosition.Bottom);
}
else
{
if (bannerViewBottom != null)
{
bannerViewBottom.Show();
bannerViewBottomShowing = true;
}
}
}
public void showAdMobBannerTopLeft()
{
if (StopShowingAdsOnLowEndDevices && deviceRam < minRamSize)
return;
if (!bannerViewTopLeftLoaded)
{
bannerViewTopLeft = showAdmobBanner(bannerViewTopLeft,
AdSize.Banner, AdPosition.TopLeft);
}
else
{
if (bannerViewTopLeft != null)
{
bannerViewTopLeft.Show();
bannerViewTopLeftShowing = true;
}
}
}
public void showAdMobBannerTopRight()
{
if (StopShowingAdsOnLowEndDevices && deviceRam < minRamSize)
return;
if (!bannerViewTopRightLoaded)
{
bannerViewTopRight = showAdmobBanner(bannerViewTopRight,
AdSize.Banner, AdPosition.TopRight);
}
else
{
if (bannerViewTopRight != null)
{
bannerViewTopRight.Show();
bannerViewTopRightShowing = true;
}
}
}
public void showAdMobBannerBottomLeft()
{
if (StopShowingAdsOnLowEndDevices && deviceRam < minRamSize)
return;
if (!bannerViewBottomLeftLoaded)
{
bannerViewBottomLeft = showAdmobBanner(bannerViewBottomLeft,
AdSize.Banner, AdPosition.BottomLeft);
}
else
{
if (bannerViewBottomLeft != null)
{
bannerViewBottomLeft.Show();
bannerViewBottomLeftShowing = true;
}
}
}
public void showAdMobBannerBottomRight()
{
if (StopShowingAdsOnLowEndDevices && deviceRam < minRamSize)
return;
if (!bannerViewBottomRightLoaded)
{
bannerViewBottomRight = showAdmobBanner(bannerViewBottomRight,
AdSize.Banner, AdPosition.BottomRight);
}
else
{
if (bannerViewBottomRight != null)
{
bannerViewBottomRight.Show();
bannerViewBottomRightShowing = true;
}
}
}
public void showAdMobBannerCenter()
{
if (StopShowingAdsOnLowEndDevices && deviceRam < minRamSize)
return;
if (!bannerViewCenterLoaded)
{
bannerViewCenter = showAdmobBanner(bannerViewCenter,
AdSize.Banner, AdPosition.Center);
}
else
{
if (bannerViewCenter != null)
{
bannerViewCenter.Show();
bannerViewCenterShowing = true;
}
}
}
public void showAdMobRectangleBannerTop()
{
if (StopShowingAdsOnLowEndDevices && deviceRam < minRamSize)
return;
}
else
{
if (bannerViewRectangleTop != null)
{
bannerViewRectangleTop.Show();
bannerViewRectangleTopShowing = true;
}
}
}
public void showAdMobRectangleBannerBottom()
{
if (StopShowingAdsOnLowEndDevices && deviceRam < minRamSize)
return;
if (!bannerViewRectangleBottomLoaded)
{
bannerViewRectangleBottom =
showAdmobBanner(bannerViewRectangleBottom, AdSize.MediumRectangle,
AdPosition.Bottom);
}
else
{
if (bannerViewRectangleBottom != null)
{
bannerViewRectangleBottom.Show();
bannerViewRectangleBottomShowing = true;
}
}
}
public void showAdMobRectangleBannerTopLeft()
{
if (StopShowingAdsOnLowEndDevices && deviceRam < minRamSize)
return;
if (!bannerViewRectangleTopLeftLoaded)
{
bannerViewRectangleTopLeft =
showAdmobBanner(bannerViewRectangleTopLeft, AdSize.MediumRectangle,
AdPosition.TopLeft);
}
else
{
if (bannerViewRectangleTopLeft != null)
{
bannerViewRectangleTopLeft.Show();
bannerViewRectangleTopLeftShowing = true;
}
}
}
public void showAdMobRectangleBannerTopRight()
{
if (StopShowingAdsOnLowEndDevices && deviceRam < minRamSize)
return;
if (!bannerViewRectangleTopRightLoaded)
{
bannerViewRectangleTopRight =
showAdmobBanner(bannerViewRectangleTopRight, AdSize.MediumRectangle,
AdPosition.TopRight);
}
else
{
if (bannerViewRectangleTopRight != null)
{
bannerViewRectangleTopRight.Show();
bannerViewRectangleTopRightShowing = true;
}
}
}
public void showAdMobRectangleBannerBottomLeft()
{
if (StopShowingAdsOnLowEndDevices && deviceRam < minRamSize)
return;
if (!bannerViewRectangleBottomLeftLoaded)
{
bannerViewRectangleBottomLeft =
showAdmobBanner(bannerViewRectangleBottomLeft, AdSize.MediumRectangle,
AdPosition.BottomLeft);
}
else
{
if (bannerViewRectangleBottomLeft != null)
{
bannerViewRectangleBottomLeft.Show();
bannerViewRectangleBottomLeftShowing = true;
}
}
}
public void showAdMobRectangleBannerBottomRight()
{
if (StopShowingAdsOnLowEndDevices && deviceRam < minRamSize)
return;
if (!bannerViewRectangleBottomRightLoaded)
{
bannerViewRectangleBottomRight =
showAdmobBanner(bannerViewRectangleBottomRight, AdSize.MediumRectangle,
AdPosition.BottomRight);
}
else
{
if (bannerViewRectangleBottomRight != null)
{
bannerViewRectangleBottomRight.Show();
bannerViewRectangleBottomRightShowing = true;
}
}
}
public void showAdMobRectangleBannerCenter()
{
if (StopShowingAdsOnLowEndDevices && deviceRam < minRamSize)
return;
if (!bannerViewRectangleCenterLoaded)
{
bannerViewRectangleCenter =
showAdmobBanner(bannerViewRectangleCenter, AdSize.MediumRectangle,
AdPosition.Center);
}
else
{
if (bannerViewRectangleCenter != null)
{
bannerViewRectangleCenter.Show();
bannerViewRectangleCenterShowing = true;
}
}
}
if (!bannerViewFullAdaptiveTopLoaded)
{
bannerViewFullAdaptiveTop =
showAdmobBanner(bannerViewFullAdaptiveTop,
AdSize.GetCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(AdSize.FullW
idth), AdPosition.Top);
}
else
{
if (bannerViewFullAdaptiveTop != null)
{
bannerViewFullAdaptiveTop.Show();
bannerViewFullAdaptiveTopShowing = true;
}
}
if (!bannerViewFullAdaptiveBottomLoaded)
{
bannerViewFullAdaptiveBottom =
showAdmobBanner(bannerViewFullAdaptiveBottom,
AdSize.GetCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(AdSize.FullW
idth), AdPosition.Bottom);
}
else
{
if (bannerViewFullAdaptiveBottom != null)
{
bannerViewFullAdaptiveBottom.Show();
bannerViewFullAdaptiveBottomShowing = true;
}
}
if (!bannerViewFullAdaptiveCentreLoaded)
{
bannerViewFullAdaptiveBottom =
showAdmobBanner(bannerViewFullAdaptiveCentre,
AdSize.GetCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(AdSize.FullW
idth), AdPosition.Center);
}
else
{
if (bannerViewFullAdaptiveCentre != null)
{
bannerViewFullAdaptiveCentre.Show();
bannerViewFullAdaptiveCentreShowing = true;
}
}
}
public void showAdmobAdpativeBannerTopCustomWidth()
{
if (StopShowingAdsOnLowEndDevices && deviceRam < minRamSize)
return;
if (!bannerViewCustomWidthAdaptiveTopLoaded)
{
bannerViewCustomWidthAdaptiveTop =
showAdmobBanner(bannerViewCustomWidthAdaptiveTop,
AdSize.GetCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(500),
AdPosition.Top);
}
else
{
if (bannerViewCustomWidthAdaptiveTop != null)
{
bannerViewCustomWidthAdaptiveTop.Show();
bannerViewCustomWidthAdaptiveTopShowing = true;
}
}
}
public void showAdmobAdpativeBannerTopLeftCustomWidth()
{
if (StopShowingAdsOnLowEndDevices && deviceRam < minRamSize)
return;
if (!bannerViewCustomWidthAdaptiveTopLeftLoaded)
{
bannerViewCustomWidthAdaptiveTopLeft =
showAdmobBanner(bannerViewCustomWidthAdaptiveTopLeft,
AdSize.GetCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(500),
AdPosition.TopLeft);
}
else
{
if (bannerViewCustomWidthAdaptiveTopLeft != null)
{
bannerViewCustomWidthAdaptiveTopLeft.Show();
bannerViewCustomWidthAdaptiveTopLeftShowing = true;
}
}
}
public void showAdmobAdpativeBannerTopRightCustomWidth()
{
if (StopShowingAdsOnLowEndDevices && deviceRam < minRamSize)
return;
if (!bannerViewCustomWidthAdaptiveTopRightLoaded)
{
bannerViewCustomWidthAdaptiveTopRight =
showAdmobBanner(bannerViewCustomWidthAdaptiveTopRight,
AdSize.GetCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(500),
AdPosition.TopRight);
}
else
{
if (bannerViewCustomWidthAdaptiveTopRight != null)
{
bannerViewCustomWidthAdaptiveTopRight.Show();
bannerViewCustomWidthAdaptiveTopRightShowing = true;
}
}
}
public void showAdmobAdpativeBannerBottomLeftCustomWidth()
{
if (StopShowingAdsOnLowEndDevices && deviceRam < minRamSize)
return;
if (!bannerViewCustomWidthAdaptiveBottomLeftLoaded)
{
bannerViewCustomWidthAdaptiveBottomLeft =
showAdmobBanner(bannerViewCustomWidthAdaptiveBottomLeft,
AdSize.GetCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(500),
AdPosition.BottomLeft);
}
else
{
if (bannerViewCustomWidthAdaptiveBottomLeft != null)
{
bannerViewCustomWidthAdaptiveBottomLeft.Show();
bannerViewCustomWidthAdaptiveBottomLeftShowing = true;
}
}
}
public void showAdmobAdpativeBannerBottomRightCustomWidth()
{
if (StopShowingAdsOnLowEndDevices && deviceRam < minRamSize)
return;
if (!bannerViewCustomWidthAdaptiveBottomRightLoaded)
{
bannerViewCustomWidthAdaptiveBottomRight =
showAdmobBanner(bannerViewCustomWidthAdaptiveBottomRight,
AdSize.GetCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(500),
AdPosition.BottomRight);
}
else
{
if (bannerViewCustomWidthAdaptiveBottomRight != null)
{
bannerViewCustomWidthAdaptiveBottomRight.Show();
bannerViewCustomWidthAdaptiveBottomRightShowing = true;
}
}
}
public void showAdmobAdpativeBannerBottomCustomWidth()
{
if (StopShowingAdsOnLowEndDevices && deviceRam < minRamSize)
return;
if (!bannerViewCustomWidthAdaptiveBottomLoaded)
{
bannerViewCustomWidthAdaptiveBottom =
showAdmobBanner(bannerViewCustomWidthAdaptiveBottom,
AdSize.GetCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(500),
AdPosition.Bottom);
}
else
{
if (bannerViewCustomWidthAdaptiveBottom != null)
{
bannerViewCustomWidthAdaptiveBottom.Show();
bannerViewCustomWidthAdaptiveBottomShowing = true;
}
}
}
public void hideAllAdmobBanners()
{
hideAdmobTopBanner();
hideAdmobBottomBanner();
hideAdmobBottomLeftBanner();
hideAdmobBottomRightBanner();
hideAdmobCenterBanner();
hideAdmobTopLeftBanner();
hideAdmobTopRightBanner();
}
public void hideAdmobTopBanner()
{
hideAdMobBanner(bannerViewTop);
bannerViewTopShowing = false;
hideAdMobBanner(bannerViewRectangleTop);
bannerViewRectangleTopShowing = false;
hideAdMobBanner(bannerViewFullAdaptiveTop);
bannerViewFullAdaptiveTopShowing = false;
hideAdMobBanner(bannerViewCustomWidthAdaptiveTop);
bannerViewCustomWidthAdaptiveTopShowing = false;
}
public void hideAdmobBottomBanner()
{
hideAdMobBanner(bannerViewBottom);
bannerViewBottomShowing = false;
hideAdMobBanner(bannerViewRectangleBottom);
bannerViewRectangleBottomShowing = false;
hideAdMobBanner(bannerViewFullAdaptiveBottom);
bannerViewFullAdaptiveBottomShowing = false;
hideAdMobBanner(bannerViewCustomWidthAdaptiveBottom);
bannerViewCustomWidthAdaptiveBottomShowing = false;
}
public void hideAdmobTopLeftBanner()
{
hideAdMobBanner(bannerViewTopLeft);
bannerViewTopLeftShowing = false;
hideAdMobBanner(bannerViewRectangleTopLeft);
bannerViewRectangleTopLeftShowing = false;
hideAdMobBanner(bannerViewCustomWidthAdaptiveTopLeft);
bannerViewCustomWidthAdaptiveTopLeftShowing = false;
}
public void hideAdmobTopRightBanner()
{
hideAdMobBanner(bannerViewTopRight);
bannerViewTopRightShowing = false;
hideAdMobBanner(bannerViewRectangleTopRight);
bannerViewRectangleTopRightShowing = false;
hideAdMobBanner(bannerViewCustomWidthAdaptiveTopRight);
bannerViewCustomWidthAdaptiveTopRightShowing = false;
}
public void hideAdmobBottomLeftBanner()
{
hideAdMobBanner(bannerViewBottomLeft);
bannerViewBottomLeftShowing = false;
hideAdMobBanner(bannerViewRectangleBottomLeft);
bannerViewRectangleBottomLeftShowing = false;
hideAdMobBanner(bannerViewCustomWidthAdaptiveBottomLeft);
bannerViewCustomWidthAdaptiveBottomLeftShowing = false;
}
public void hideAdmobBottomRightBanner()
{
hideAdMobBanner(bannerViewBottomRight);
bannerViewBottomRightShowing = false;
hideAdMobBanner(bannerViewRectangleBottomRight);
bannerViewRectangleBottomRightShowing = false;
hideAdMobBanner(bannerViewCustomWidthAdaptiveBottomRight);
bannerViewCustomWidthAdaptiveBottomRightShowing = false;
}
public void hideAdmobCenterBanner()
{
hideAdMobBanner(bannerViewCenter);
bannerViewCenterShowing = false;
hideAdMobBanner(bannerViewRectangleCenter);
bannerViewRectangleCenterShowing = false;
hideAdMobBanner(bannerViewFullAdaptiveCentre);
bannerViewFullAdaptiveCentreShowing = false;
hideAdMobBanner(bannerViewCustomWidthAdaptiveCentre);
bannerViewCustomWidthAdaptiveCentreShowing = false;
}
#endregion
#region Interstitials
void tryToLoadAllInterstitials()
{
Invoke("loadAdMobInterstital0", 0.5f);
Invoke("loadAdMobInterstital1", 1f);
Invoke("loadAdMobInterstital2", 1.5f);
Invoke("loadAdMobInterstital3", 2f);
Invoke("loadAdMobInterstital4", 2.5f);
}
if (interstitialAd0 != null)
{
interstitialAd0.Destroy();
interstitialAd0 = null;
}
if (ShowTestAds)
{
loadInterstitialAdCustom0("ca-app-pub-
3940256099942544/1033173712");
}
else
{
if (interstitialAd0 != null)
{
if (!interstitialAd0.CanShowAd())
{
if (admobInterstitialIds.Length > 0)
{
loadInterstitialAdCustom0(admobInterstitialIds[0]);
}
}
}
else
{
if (admobInterstitialIds.Length > 0)
{
loadInterstitialAdCustom0(admobInterstitialIds[0]);
}
}
}
}
void loadAdMobInterstital1()
{
if (interstitialAd1 != null)
{
interstitialAd1.Destroy();
interstitialAd1 = null;
}
if (ShowTestAds)
{
loadInterstitialAdCustom1("ca-app-pub-
3940256099942544/1033173712");
}
else
{
if (interstitialAd1 != null)
{
if (!interstitialAd1.CanShowAd())
{
if (admobInterstitialIds.Length > 1)
{
loadInterstitialAdCustom1(admobInterstitialIds[1]);
}
}
}
else
{
if (admobInterstitialIds.Length > 1)
{
loadInterstitialAdCustom1(admobInterstitialIds[1]);
}
}
}
}
void loadAdMobInterstital2()
{
if (interstitialAd2 != null)
{
interstitialAd2.Destroy();
interstitialAd2 = null;
}
if (ShowTestAds)
{
loadInterstitialAdCustom2("ca-app-pub-
3940256099942544/1033173712");
}
else
{
if (interstitialAd2 != null)
{
if (!interstitialAd2.CanShowAd())
{
if (admobInterstitialIds.Length > 2)
{
loadInterstitialAdCustom2(admobInterstitialIds[2]);
}
}
}
else
{
if (admobInterstitialIds.Length > 2)
{
loadInterstitialAdCustom2(admobInterstitialIds[2]);
}
}
}
}
void loadAdMobInterstital3()
{
if (interstitialAd3 != null)
{
interstitialAd3.Destroy();
interstitialAd3 = null;
}
if (ShowTestAds)
{
loadInterstitialAdCustom3("ca-app-pub-
3940256099942544/1033173712");
}
else
{
if (interstitialAd3 != null)
{
if (!interstitialAd3.CanShowAd())
{
if (admobInterstitialIds.Length > 3)
{
loadInterstitialAdCustom3(admobInterstitialIds[3]);
}
}
}
else
{
if (admobInterstitialIds.Length > 3)
{
loadInterstitialAdCustom3(admobInterstitialIds[3]);
}
}
}
}
void loadAdMobInterstital4()
{
if (interstitialAd4 != null)
{
interstitialAd4.Destroy();
interstitialAd4 = null;
}
if (ShowTestAds)
{
loadInterstitialAdCustom4("ca-app-pub-
3940256099942544/1033173712");
}
else
{
if (interstitialAd4 != null)
{
if (!interstitialAd4.CanShowAd())
{
if (admobInterstitialIds.Length > 4)
{
loadInterstitialAdCustom4(admobInterstitialIds[4]);
}
}
}
else
{
if (admobInterstitialIds.Length > 4)
{
loadInterstitialAdCustom4(admobInterstitialIds[4]);
}
}
}
}
private void RegisterInterEvents0(InterstitialAd ad)
{
ad.OnAdImpressionRecorded += () =>
{
isAdAlreadyShowing = true;
};
ad.OnAdFullScreenContentClosed += () =>
{
loadAdMobInterstital0();
isAdAlreadyShowing = false;
};
}
private void RegisterInterEvents1(InterstitialAd ad)
{
ad.OnAdImpressionRecorded += () =>
{
isAdAlreadyShowing = true;
};
ad.OnAdFullScreenContentClosed += () =>
{
loadAdMobInterstital1();
isAdAlreadyShowing = false;
};
}
private void RegisterInterEvents2(InterstitialAd ad)
{
ad.OnAdImpressionRecorded += () =>
{
isAdAlreadyShowing = true;
};
ad.OnAdFullScreenContentClosed += () =>
{
loadAdMobInterstital2();
isAdAlreadyShowing = false;
};
}
private void RegisterInterEvents3(InterstitialAd ad)
{
ad.OnAdImpressionRecorded += () =>
{
isAdAlreadyShowing = true;
};
ad.OnAdFullScreenContentClosed += () =>
{
loadAdMobInterstital3();
isAdAlreadyShowing = false;
};
}
private void RegisterInterEvents4(InterstitialAd ad)
{
ad.OnAdImpressionRecorded += () =>
{
isAdAlreadyShowing = true;
};
ad.OnAdFullScreenContentClosed += () =>
{
loadAdMobInterstital4();
isAdAlreadyShowing = false;
};
}
bool showAdmobInter0()
{
if (interstitialAd0 != null)
{
if (interstitialAd0.CanShowAd())
{
interstitialAd0.Show();
tryToLoadAllInterstitials();
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
bool showAdmobInter1()
{
if (interstitialAd1 != null)
{
if (interstitialAd1.CanShowAd())
{
interstitialAd1.Show();
tryToLoadAllInterstitials();
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
bool showAdmobInter2()
{
if (interstitialAd2 != null)
{
if (interstitialAd2.CanShowAd())
{
interstitialAd2.Show();
tryToLoadAllInterstitials();
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
bool showAdmobInter3()
{
if (interstitialAd3 != null)
{
if (interstitialAd3.CanShowAd())
{
interstitialAd3.Show();
tryToLoadAllInterstitials();
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
bool showAdmobInter4()
{
if (interstitialAd4 != null)
{
if (interstitialAd4.CanShowAd())
{
interstitialAd4.Show();
tryToLoadAllInterstitials();
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
#endregion
#region RewardedInterstitials
void loadAdmobRewardedInterstitial()
{
if (StopShowingAdsOnLowEndDevices && deviceRam < minRamSize)
return;
if (rewardedInterstitialAD != null)
{
rewardedInterstitialAD.Destroy();
rewardedInterstitialAD = null;
}
RewardedInterstitialAd.Load(ShowTestAds ? "ca-app-pub-
3940256099942544/5354046379" : admobRewardedInterstitialID, CreateAdRequest(),
(RewardedInterstitialAd ad, LoadAdError error) =>
{
// if error is not null, the load request failed.
if (error != null || ad == null)
{
return;
}
rewardedInterstitialAD = ad;
RegisterRewardedInterEventHandlers(ad);
});
ad.OnAdFullScreenContentClosed += () =>
{
isAdAlreadyShowing = false;
loadAdmobRewardedInterstitial();
};
#endregion
#region AppOpenAd
bool isShowingAppOpenAd;
private bool IsAdAvailable
{
get
{
return thisAppOpenAd != null && thisAppOpenAd.CanShowAd() /*&&
(System.DateTime.UtcNow - loadTime).TotalHours < 4*/;
}
}
if (thisAppOpenAd != null)
{
thisAppOpenAd.Destroy();
thisAppOpenAd = null;
}
//var adRequest = new AdRequest();
AppOpenAd.Load(ShowTestAds ? "ca-app-pub-3940256099942544/3419835294"
: appOpenAdID,screenOrientation, CreateAdRequest(),
(AppOpenAd ad, LoadAdError error) =>
{
// if error is not null, the load request failed.
if (error != null || ad == null)
{
return;
}
thisAppOpenAd = ad;
RegisterAppOpenEventHandlers(ad);
});
}
ad.OnAdFullScreenContentClosed += () =>
{
thisAppOpenAd = null;
isShowingAppOpenAd = false;
LoadAppOpenAd();
ShowBannersForAppOpenAd();
};
if (!IsAdAvailable)
LoadAppOpenAd();
if (!IsAdAvailable || isShowingAppOpenAd)
return;
thisAppOpenAd.Show();
HideBannersForAppOpenAd();
}
void HideBannersForAppOpenAd()
{
if (StopShowingAdsOnLowEndDevices && deviceRam < minRamSize)
return;
void ShowBannersForAppOpenAd()
{
if (StopShowingAdsOnLowEndDevices && deviceRam < minRamSize)
return;
#region AdmobRewardedVideo
void LoadVideoAD()
{
if (StopShowingAdsOnLowEndDevices && deviceRam < minRamSize)
return;
if (videoAD != null)
{
videoAD.Destroy();
videoAD = null;
}
RewardedAd.Load(ShowTestAds ? "ca-app-pub-3940256099942544/5224354917"
: admobRewardedVideoID, CreateAdRequest(),
(RewardedAd ad, LoadAdError error) =>
{
if (error != null || ad == null)
{
return;
}
videoAD = ad;
RegisterRewardedVideoEventHandlers(ad);
});
}
private void RegisterRewardedVideoEventHandlers(RewardedAd ad)
{
ad.OnAdImpressionRecorded += () =>
{
isAdAlreadyShowing = true;
};
ad.OnAdFullScreenContentClosed += () =>
{
isAdAlreadyShowing = false;
LoadVideoAD();
};
}
public bool CheckIfAdmobRewardVideoRewardInterIsLoaded()
{
if (StopShowingAdsOnLowEndDevices && deviceRam < minRamSize)
return false;
if (videoAD != null)
{
if (videoAD.CanShowAd())
return true;
else if (checkIfAdmobRewardedInterstitialIsLoaded())
return true;
return false;
}
else if (checkIfAdmobRewardedInterstitialIsLoaded())
{
return true;
}
return false;
}
if (videoAD != null)
{
if (videoAD.CanShowAd())
ShowAdmobRewardedVideoAd();
else if (checkIfAdmobRewardedInterstitialIsLoaded())
{
ShowAdmobRewardedInterstitial();
LoadVideoAD();
}
else
{
LoadVideoAD();
Invoke("loadAdmobRewardedInterstitial", 1f);
}
}
else if (checkIfAdmobRewardedInterstitialIsLoaded())
{
ShowAdmobRewardedInterstitial();
LoadVideoAD();
}
else
{
LoadVideoAD();
Invoke("loadAdmobRewardedInterstitial", 1f);
}
}
if (videoAD != null)
{
if (videoAD.CanShowAd())
{
}
else
{
LoadVideoAD();
}
}
else
{
LoadVideoAD();
}
}
public bool CheckIfAdmobRewardedVideoIsReady()
{
if (StopShowingAdsOnLowEndDevices && deviceRam < minRamSize)
return false;
if (videoAD != null)
{
if (videoAD.CanShowAd())
{
return true;
}
else
{
LoadVideoAD();
return false;
}
}
return false;
}
#endregion
}