InAppPurchaseManager (Unity IAP v5)

Overview

Implements a single non‑consumable purchase: Remove Ads (productIdRemoveAds = "removeads"). Caches entitlement in PlayerPrefs for offline first‑launch, exposes Unity Atoms for entitlement gating, and integrates with Ads by disabling requests when the user is entitled.

Atoms / Events

  • BoolReference adsRemoved — entitlement state.
  • BoolReference adsCanRequestAds — forced false when entitled.
  • VoidEvent purchaseRemoveAds — UI “Buy” → triggers purchase.
  • VoidEvent onRemoveAdsPurchased — raised after confirmed grant.
  • UnityEventsonInitializationSucceeded/Failed, onPriceUpdated, onPurchaseSucceeded/Failed/Pending, onRestoreSucceeded/Failed, onEntitlementRevoked.

Settings

  • useLocalCache (default true) and cacheKey ("paidVersion") — cache entitlement in PlayerPrefs.
  • resetOnBootForDebug — clears cache and atoms on boot (for clean QA sessions).
  • productIdRemoveAds — Google Play product id ("removeads").

Public API

  • bool BootEarlyHint() — reads cached entitlement on Awake to early‑gate Ads (sets adsRemoved and adsCanRequestAds=false if paid).
  • void BuyRemoveAds() — starts purchase; guarded against “already owned”/“not initialized”.
  • void RestorePurchases() — invokes platform restore API (where supported).
  • bool ShouldInitializeAds() — helper gate (!HasAdsRemoved()).
  • bool HasAdsRemoved() — returns entitlement from live state or early cache.
  • void RefreshEntitlements()StoreController.FetchPurchases() (also called on app focus).

Lifecycle

  • Awake() — optional debug reset, DontDestroyOnLoad, BootEarlyHint, register buy event.
  • Start() — clamps atoms from entitlement and InitializePurchasing().
  • Handles Store events (products fetched, purchases fetched, pending/failed/confirmed) and persists via SetEntitlement().

Integration Notes

  • When entitlement flips to true, the manager sets adsCanRequestAds=false so AdMobBootstrap won’t request ads.
  • The Interstitial policy also checks PlayerPrefs["paidVersion"] as an extra guard.