AdMobBootstrap

Overview

Initializes Google Mobile Ads and defers all ad requests until UMP says it’s legal to do so (adsCanRequestAds == true). Preloads a banner and an interstitial, exposes an event-driven TryShowInterstitial(), and keeps a visibility atom updated for your UI.

Platform

  • Android runtime only. Skips in Editor and non-Android builds.

Atoms / Events

  • BoolReference adsCanRequestAds — gate for requesting ads (from UMP).
  • BoolReference bannerVisibletrue while a banner is loaded.
  • BoolReference interstitialReadytrue when an interstitial is preloaded and can show.
  • VoidEvent requestInterstitialEvent — hook this to request showing an interstitial.

Behavior

  1. On Awake():
    • If PlayerPrefs["paidVersion"] == 1, do nothing (Remove Ads).
    • Initialize Mobile Ads; set test device IDs if provided.
  2. After SDK init, wait until adsCanRequestAds == true (UMP ready).
  3. LoadBanner() and PreloadInterstitial():
    • Banner events update bannerVisible.
    • Interstitial events keep interstitialReady updated and auto-preload after closing.
  4. TryShowInterstitial() displays the interstitial only if it can show.

Notes

  • Uses MobileAds.RaiseAdEventsOnUnityMainThread = true.
  • Replace demo/test ad unit IDs with your own in production.