From package-guide
This skill should be used when the user asks to "add ads", "implement AdMob", "add rewarded ads", "integrate Google Mobile Ads", "add ad system", "implement rewarded video", "add consent manager", "set up UMP", or needs to implement any advertising system in a Unity project. Provides a complete implementation workflow for Google AdMob rewarded ads with clean architecture patterns.
npx claudepluginhub flashwade03/unity-dev-vibecoding-with-awesome-assets --plugin package-guideThis skill uses the workspace's default tool permissions.
Implement a Google AdMob rewarded ad system with GDPR consent handling (UMP SDK).
Searches, retrieves, and installs Agent Skills from prompts.chat registry using MCP tools like search_skills and get_skill. Activates for finding skills, browsing catalogs, or extending Claude.
Searches prompts.chat for AI prompt templates by keyword or category, retrieves by ID with variable handling, and improves prompts via AI. Use for discovering or enhancing prompts.
Checks Next.js compilation errors using a running Turbopack dev server after code edits. Fixes actionable issues before reporting complete. Replaces `next build`.
Implement a Google AdMob rewarded ad system with GDPR consent handling (UMP SDK). The architecture uses a callback-based request pattern: callers pass reward/failure callbacks through an event, and AdManager handles the ad lifecycle transparently.
App Start
|
v
ConsentManager.RequestConsent()
|
v (consent complete)
MobileAds.Initialize()
|
v
LoadRewardedAd() <---- auto-reload after each show
|
v
_adReadyVariable = true
|
[User taps ad button] (only enabled when adReady == true)
|
v
Event.Raise(new AdRequest(onRewarded, onFailed))
|
v
AdManager.Show() --> OnUserEarnedReward --> request.OnRewarded()
--> OnAdFailed --> request.OnFailed()
Key Principles:
Import Google Mobile Ads Unity Plugin via .unitypackage or UPM.
Configure GoogleMobileAdsSettings asset with App IDs.
A plain C# class carrying callbacks:
using System;
public class AdRequest
{
public Action OnRewarded { get; }
public Action OnFailed { get; }
public AdRequest(Action onRewarded, Action onFailed = null)
{
OnRewarded = onRewarded;
OnFailed = onFailed;
}
}
Handles UMP SDK consent flow before ad initialization:
public class ConsentManager : MonoBehaviour
{
private Action _onConsentCompleted;
public void RequestConsent(Action onConsentCompleted)
{
_onConsentCompleted = onConsentCompleted;
#if UNITY_ANDROID || UNITY_IOS
var requestParameters = new ConsentRequestParameters();
ConsentInformation.Update(requestParameters, OnConsentInfoUpdated);
#else
_onConsentCompleted?.Invoke();
#endif
}
// ... platform-specific consent form handling
}
Core lifecycle:
Awake() - Set _adReadyVariable = falseStart() - Call _consentManager.RequestConsent(InitializeAds)OnEnable() - Subscribe to ad request eventOnDisable() - Unsubscribe from ad request eventCritical patterns:
InitializeAds() - MobileAds.Initialize(), then LoadRewardedAd()LoadRewardedAd() - Destroy old ad, set ready=false, load new oneHandleAdRequest(AdRequest) - Store request, call _rewardedAd.Show()_currentRequest.OnRewarded?.Invoke()Each caller (popup, button, etc.) needs:
_adReadyVariable for button enable/disableevent.Raise(new AdRequest(onSuccess, onFailure))In #else (non-mobile) blocks, simulate ad success:
#else
Debug.Log("[AdManager] Editor mode - simulating ad success.");
_currentRequest?.OnRewarded?.Invoke();
_currentRequest = null;
#endif
Set _adReadyVariable = true in editor mode so buttons are enabled.
Use test IDs during development:
#if UNITY_ANDROID
private const string AD_UNIT_ID = "ca-app-pub-3940256099942544/5224354917"; // Test
#elif UNITY_IOS
private const string AD_UNIT_ID = "ca-app-pub-3940256099942544/1712485313"; // Test
#endif
Pre-release: Replace with real Ad Unit IDs from AdMob console.
Configure Assets/GoogleMobileAds/Resources/GoogleMobileAdsSettings:
ca-app-pub-XXXXX~XXXXXca-app-pub-XXXXX~XXXXXImportant: App ID uses ~ (tilde), Ad Unit ID uses / (slash).
Document all SerializeField assignments, SOAP asset creation, and pre-release checklist.
Create ScriptableEvent<AdRequest> subclass. See references/implementation-patterns.md.
Use C# events or direct reference:
// Direct reference approach
adManager.ShowRewardedAd(new AdRequest(onReward, onFail));
// Or static event approach
AdManager.OnAdRequested?.Invoke(new AdRequest(onReward, onFail));
| Pitfall | Solution |
|---|---|
| Ad buttons active when no ad loaded | Gate buttons on _adReadyVariable.Value == true |
| Consent form blocks forever | Add timeout, invoke callback on error too |
| Ads don't work in Editor | Use #if UNITY_ANDROID || UNITY_IOS guards, simulate in else block |
| Mock ad panel blocks input | Set CanvasGroup blocksRaycasts = false and Image raycastTarget = false when hidden |
| Ad not reloading after show | Register OnAdFullScreenContentClosed to trigger LoadRewardedAd() |
| First ad takes long to load | Start loading in Start() via consent flow, not on first request |
references/implementation-patterns.md - Complete code templates with SOAP and non-SOAP variants