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
bannerVisible—truewhile a banner is loaded. - BoolReference
interstitialReady—truewhen an interstitial is preloaded and can show. - VoidEvent
requestInterstitialEvent— hook this to request showing an interstitial.
Behavior
- On
Awake():- If
PlayerPrefs["paidVersion"] == 1, do nothing (Remove Ads). - Initialize Mobile Ads; set test device IDs if provided.
- If
- After SDK init, wait until
adsCanRequestAds == true(UMP ready). - LoadBanner() and PreloadInterstitial():
- Banner events update
bannerVisible. - Interstitial events keep
interstitialReadyupdated and auto-preload after closing.
- Banner events update
- 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.