Refactor bloated AGENTS.md, CLAUDE.md, or similar agent instruction files to follow progressive disclosure principles. Splits monolithic files into organized, linked documentation.
中文简介正在准备中。当前显示原文说明。
Implement, configure, and debug Unity In-App Purchases (IAP) — store connection, product catalog, consumable/non-consumable/subscription purchases, two-step pending-confirm flow, receipt validation, entitlement checking, restore transactions, Apple extensions (promotional purchases, Ask-to-Buy, code redemption), and Google Play extensions (subscription upgrade/downgrade), D2C Capabilities(direct to customer), 3rd party payment provider (Stripe/Coda) via Unity IAP/Unity Cloud. Use when the user needs to add, modify, debug, or migrate from native Android/iOS billing, 3rd party packages(RevenueCat/Adapty/Essential Kit/Unipay supported) to IAP. Triggers on microtransactions (MTX), monetization, real-money purchases, store purchases, buying items, support D2C, purchase via Stripe/Coda, migrate from native billing(Google's BillingClient or Apple's StoreKit/SKPaymentQueue/SKProduct)/RevenueCat/Adapty/EssentialKit/Unipay.
中文简介正在准备中。当前显示原文说明。
实测评分 未实测
查看安装方法安装前可以查看交给 AI 代理的指令内容。
Namespace: UnityEngine.Purchasing | Security: UnityEngine.Purchasing.Security
Package: com.unity.purchasing
Unity IAP has its own initialization path via UnityIAPServices.StoreController() → store.Connect(). It does not require UnityServices.InitializeAsync(), but they can coexist if your project uses other UGS services. If Analytics is present and InitializeAsync() is called, IAP will automatically send transaction events.
Always read references/pre-check.md first. It scans the project for third-party IAP packages, native Google Billing, and existing Unity IAP versions, then routes to the correct path. Do not read any other reference file or make any changes until routing is resolved.
IAPProductCatalog.json (schema, decimal serialization, refresh): See references/codeless-catalog.mdRead reference files on demand — only when you need specific API signatures, platform extension details, or migration mappings.
StoreController via UnityIAPServices.StoreController() (or individual services via DefaultStore(), DefaultProduct(), DefaultPurchase())Connect()await store.Connect() to connect to the platform storeOnStoreConnected, call store.FetchProducts(List<ProductDefinition>) to load the catalogOnProductsFetched, products are ready for display and purchaseUse Awake() for initialization — ensures IAP is ready before other Start() methods.
Product types: ProductType.Consumable, ProductType.NonConsumable, ProductType.Subscription.
Define products as List<ProductDefinition> and pass to store.FetchProducts(). Use StoreSpecificIds when product IDs differ across Apple/Google stores. For complex catalogs, use CatalogProvider to manage product sets and store-specific IDs.
| Method | Behavior |
|---|---|
GetProducts() | Returns the cached product list (synchronous, stale if FetchProducts not called) |
FetchProducts() | Queries the store for fresh pricing/availability and updates the cache |
GetProductById(id) | Returns a single cached product by ID |
These are NOT interchangeable. Always call FetchProducts() first before relying on GetProducts().
IAP v5 uses a mandatory two-step flow: Pending → Confirm.
store.PurchaseProduct(product) — initiates the platform purchase dialogOnPurchasePending fires — you receive a PendingOrderstore.ConfirmPurchase(pendingOrder) — finalizes the transactionOnPurchaseConfirmed fires — receives Order base type; pattern-match ConfirmedOrder (success) vs FailedOrder (confirmation failed)You MUST call ConfirmPurchase(pendingOrder) after granting content. Unconfirmed purchases are re-delivered on next app launch to prevent lost purchases.
De-duplication: OnPurchasePending may fire multiple times for the same purchase (e.g., app restart before confirmation). Always check if content was already granted.
Consumables: Confirmed consumable purchases are NOT returned by FetchPurchases. Track consumable grants yourself (e.g., in Cloud Save or Economy).
Deferred purchases: OnPurchaseDeferred fires for Ask-to-Buy (iOS) and Google Play deferred purchases. Do NOT grant content — wait for OnPurchasePending when approved.
store.RestoreTransactions(callback) re-delivers non-consumable and subscription purchases. Each restored purchase triggers OnPurchasePending.
Required on iOS for Apple App Store compliance — add a "Restore Purchases" button.
Apple non-renewable subscriptions cannot be restored via RestoreTransactions. Track these server-side.
| Platform | Approach |
|---|---|
| Google Play | CrossPlatformValidator with GooglePlayTangle.Data() — local validation supported |
| Apple (StoreKit 2) | Local validation is a no-op. Use order.Info.Apple?.jwsRepresentation for server-side validation |
Generate tangle data via Services > In-App Purchasing > Receipt Validation Obfuscator in the Unity Editor.
Use when you don't have the Order and want to know the status of a specific product (replaces v4's product.hasReceipt). If you already have the Order, check its type instead: PendingOrder maps to EntitledUntilConsumed (consumables) or EntitledButNotFinished (non-consumables/subscriptions), ConfirmedOrder maps to FullyEntitled.
Call store.CheckEntitlement(product) and handle store.OnCheckEntitlement. Check entitlement.Status == EntitlementStatus.FullyEntitled.
EntitlementStatus values: FullyEntitled, EntitledUntilConsumed, EntitledButNotFinished, NotEntitled, Unknown.
store.FetchPurchases() retrieves all current purchases from the store. Useful at app startup.
| Method | Behavior |
|---|---|
GetPurchases() | Returns the cached purchase list |
FetchPurchases() | Queries the store for current purchases and overwrites the cached list |
FetchPurchases() replaces the entire cached list on each call. Only non-consumables and subscriptions are re-fetched — confirmed consumables are not returned (see Two-Step Purchase Flow above).
Subscription info is on IPurchasedProductInfo, accessed via order.Info.PurchasedProductInfo — NOT on CartItem (CartItem only has Product and Quantity).
IsSubscribed() returns Result enum (True/False/Unsupported), NOT bool. Use == Result.True for null-safe comparison.
Always subscribe to BOTH success and failure events. Not subscribing to failure events generates runtime warnings.
| Call | Success Event | Failure Event (REQUIRED) |
|---|---|---|
FetchProducts() | OnProductsFetched | OnProductsFetchFailed |
FetchPurchases() | OnPurchasesFetched | OnPurchasesFetchFailed |
Connect() | OnStoreConnected | OnStoreDisconnected |
PurchaseProduct() | OnPurchasePending | OnPurchaseFailed |
CheckEntitlement() | OnCheckEntitlement | — |
Always subscribe to OnPurchaseDeferred — fires for Ask-to-Buy (iOS) and Google Play deferred purchases. Not subscribing silently drops deferred purchases.
Subscribe to events BEFORE calling Connect() — pending purchases from a previous session may fire immediately.
These property names are NOT interchangeable — using the wrong one causes CS1061:
| Type | Field | Property | NOT |
|---|---|---|---|
StoreConnectionFailureDescription | .message | .Message | .reason |
ProductFetchFailed | — | .FailureReason, .FailedFetchProducts | .Message |
FailedOrder | — | .FailureReason, .Details | — |
PurchasesFetchFailureDescription | .message, .failureReason | .Message, .FailureReason | — |
After writing code that uses this package:
IStoreListener, UnityPurchasing.Initialize, ConfigurationBuilder).OnStoreConnectionFailed (use OnStoreDisconnected), do NOT pass callbacks to FetchProducts/FetchPurchases (use events), do NOT use product.receipt (use order.Info.Receipt).Connect() (see Required Event Subscriptions table above).OnPurchasePending → grant content → ConfirmPurchase(pendingOrder).OnProductsFetched/OnProductsFetchFailed, OnStoreConnected/OnStoreDisconnected, etc.).IsSubscribed() is compared with == Result.True, not cast to bool..Updated suffix) to avoid CS0101/CS0111 compilation errors.OnAuthAccountChanged (v5.4+): verify the handler re-fetches products and purchases from scratch — Unity IAP clears both caches before raising this event. Do not read GetProducts() or GetPurchases() inside the handler.还没有评价。欢迎分享你的使用感受。
无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。
还没有评论。来写第一条吧。
Refactor bloated AGENTS.md, CLAUDE.md, or similar agent instruction files to follow progressive disclosure principles. Splits monolithic files into organized, linked documentation.
中文简介正在准备中。当前显示原文说明。
Build and operate a live game using Unity Services. Use when the user needs to implement, connect, or debug backend-driven features — battle passes, achievements, player progression, cloud saves, leaderboards, matchmaking, virtual economies, server-authoritative logic, anti-cheat, player accounts and authentication, remote configuration, feature flags, A/B testing, analytics, or cloud resource deployment. Triggers on live-ops, live service, backend, server authority, cloud code, cloud save, remote config, player data, retention, monetization loop, season pass, ranking, multiplayer sessions, lobbies, or any Unity Services integration.
中文简介正在准备中。当前显示原文说明。
Kern engine critical invariants: coordinate system, UI Toolkit positioning, RenderTexture blit, LifetimeScope/scene structure, VolumeProfile editor API, camera pixel-grid alignment, performance analysis rules, profiler interpretation, and the no-fallback policy. Use when touching coordinates, WorldToScreen, UI element anchoring, RenderTexture, LifetimeScope, VolumeProfile, camera, FPS analysis, Profiler markers, or any code near an "invariant" comment. Triggers on: CoordinateUtils, MapManager.WorldHeight, RuntimePanelUtils, CameraTransformWorldToPanel, WorldToLocal, PositionWriteEpsilon, CameraPixelGridAligner, LifetimeScope, RegisterComponent, VolumeProfile, AssetDatabase.AddObjectToAsset, EditorLoop, VSync, fallback, paper white, FPS, frame time.
中文简介正在准备中。当前显示原文说明。
Kern project C# conventions, namespace rules, DI/VContainer patterns, and assembly layer boundaries. Use when writing, editing, or reviewing any C# file — MonoBehaviours, ScriptableObjects, services, contracts, factories, or editor scripts. Triggers on: namespace, nullable, asmdef, VContainer, RegisterComponent, IObjectResolver, composition root, Kern.Contracts, primary constructor, record struct, SA1513, _camelCase, PascalCase, asmref, MonoScript.GetClass.
中文简介正在准备中。当前显示原文说明。
Synchronize and compile FMOD Studio banks into StreamingAssets
中文简介正在准备中。当前显示原文说明。
Kern HDR/color pipeline contract: scene-referred linear working space, paper white units, radiance format rules, URP output transform ownership, DisplayFinal perceptual/linear space, UI brightness, HDR calibration screen, safe-start HDR switch, and HDROutputController usage. Use when touching lighting shaders, glow, bloom, tonemapping, post-processing, color grading, LUT, display output, UI colors, calibration, or any code with DisplaySettings / HDROutput / PaperWhite / Tonemapping / CompositeFinal / DisplayFinal / VisualTuning. Triggers on: saturate on radiance, clamp color, sRGB in shader, UNorm light buffer, ARGBHalf, paper white, HDROutputReconciler, VisualTuning, BT2390, detectPaperWhite, HDRCalibrationScreen, HDRSwitchPending, HDROutputSettings.
中文简介正在准备中。当前显示原文说明。