Communitygithub.com

unity-technologies/implement-in-app-purchases

Unity In-App Purchasing (IAP)の実装、設定、デバッグを行います。ストア接続、プロダクトカタログ、消費型・非消費型・サブスクリプション購入、2段階確認フロー、レシート検証、エンタイトルメント確認、リストア処理、Apple拡張機能(プロモーション購入、Ask-to-Buy、コード利用)、Google Play拡張機能(サブスクリプションのアップグレード/ダウングレード)、D2C機能、サードパーティ決済プロバイダ(Stripe/Coda)をUnity IAP/Unity Cloud経由でサポートします。

implement-in-app-purchases とは?

このスキルは、Unityプロジェクトにおいてアプリ内課金(IAP)システムを実装、設定、デバッグするための包括的なガイドです。Unity IAP v5の2段階購入フロー(Pending→Confirm)を中心に、ストア接続、プロダクトカタログの取得、消費型/非消費型/サブスクリプション購入、レシート検証、エンタイトルメント確認、トランザクションのリストアといった主要機能をカバーします。Apple StoreKit 2やGoogle BillingClientといったネイティブ課金システム、RevenueCat、Adapty、Essential Kit、UniPayなどのサードパーティパッケージからUnity IAPへの移行手順も詳細に説明しています。また、Stripe/Codaを利用したD2C(Direct-to-Consumer)機能の実装もサポートしており、開発者はこのスキルを使用して、アプリの収益化を最適化し、クロスプラットフォームでの一貫した課金体験を提供できます。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/unity-technologies/skills/tree/main/skills/implement-in-app-purchases

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

Unity In-App Purchasing

名前空間: UnityEngine.Purchasing | セキュリティ: UnityEngine.Purchasing.Security パッケージ: com.unity.purchasing

Unity IAPには独自の初期化パスがあります UnityIAPServices.StoreController() → store.Connect() 経由です。UnityServices.InitializeAsync() は必要ありませんが、プロジェクトで他のUGSサービスを使用している場合は共存可能です。Analyticsが存在し、InitializeAsync() が呼び出された場合、IAPは自動的にトランザクションイベントを送信します。

始める前に

最初に必ず references/pre-check.md を読んでください。 プロジェクト内のサードパーティIAPパッケージ、ネイティブGoogle Billing、既存のUnity IAPバージョンをスキャンし、適切なパスにルーティングします。ルーティングが解決されるまで、他のリファレンスファイルを読んだり変更を加えたりしないでください。

詳細リファレンス

リファレンスファイルはオンデマンドで読み取ってください — 特定のAPIシグネチャ、プラットフォーム拡張機能の詳細、または移行マッピングが必要な場合のみです。

初期化フロー

  1. UnityIAPServices.StoreController() を使用して StoreController を取得します(または個別のサービスを DefaultStore()、DefaultProduct()、DefaultPurchase() 経由で取得)
  2. Connect() を呼び出す前に、必要なすべてのイベントをサブスクライブします(以下の必須イベントサブスクリプションを参照)
  3. await store.Connect() でプラットフォームストアに接続します
  4. OnStoreConnected で、store.FetchProducts(List<ProductDefinition>) を呼び出してカタログをロードします
  5. OnProductsFetched で、製品が表示と購入の準備が整います

初期化には Awake() を使用してください — 他の Start() メソッドの前にIAPの準備が確実に行われます。

製品タイプ: ProductType.Consumable、ProductType.NonConsumable、ProductType.Subscription。

製品の取得

製品を List<ProductDefinition> として定義し、store.FetchProducts() に渡します。Apple/Googleストア間で製品IDが異なる場合は StoreSpecificIds を使用します。複雑なカタログの場合は、CatalogProvider を使用して製品セットとストア固有のIDを管理します。

メソッド動作
GetProducts()キャッシュされた製品リストを返します(同期的、FetchProducts が呼び出されていない場合は古い可能性あり)
FetchProducts()ストアに最新の価格/在庫状況を照会し、キャッシュを更新します
GetProductById(id)IDで単一のキャッシュされた製品を返します

これらは互換性がありません。GetProducts() に依存する前に、常に最初に FetchProducts() を呼び出してください。

2段階購入フロー

IAP v5では必須の2段階フローを使用します: Pending → Confirm。

  1. store.PurchaseProduct(product) — プラットフォームの購入ダイアログを開始します
  2. OnPurchasePending が発火 — PendingOrder を受け取ります
  3. レシートを検証し、プレイヤーにコンテンツを付与します
  4. store.ConfirmPurchase(pendingOrder) — トランザクションを確定します
  5. OnPurchaseConfirmed が発火 — Order ベースタイプを受け取ります;ConfirmedOrder(成功)と FailedOrder(確認失敗)をパターンマッチングします

コンテンツを付与した後は、必ず ConfirmPurchase(pendingOrder) を呼び出してください。 確認されていない購入は、購入の消失を防ぐため、次回アプリ起動時に再配信されます。

重複排除: OnPurchasePending は同じ購入に対して複数回発火する可能性があります(例: 確認前のアプリ再起動)。コンテンツが既に付与されているかどうかを常に確認してください。

消費型アイテム: 確認された消費型アイテムの購入は FetchPurchases では返されません。消費型アイテムの付与は自分で追跡してください(例: Cloud Save や Economy を使用)。

延期購入: OnPurchaseDeferred は Ask-to-Buy(iOS)および Google Play の延期購入に対して発火します。コンテンツを付与しないでください — 承認された場合の OnPurchasePending を待ちます。

トランザクションのリストア

store.RestoreTransactions(callback) は非消費型およびサブスクリプションの購入を再配信します。リストアされた各購入は OnPurchasePending をトリガーします。

iOSではApple App Store準拠のために必須です — 「購入を復元」ボタンを追加してください。

Appleの非更新サブスクリプションは RestoreTransactions 経由では復元できません。サーバー側で追跡してください。

レシート検証

プラットフォームアプローチ
Google PlayCrossPlatformValidator と GooglePlayTangle.Data() — ローカル検証がサポートされています
Apple(StoreKit 2)ローカル検証はノーオペレーション(何もしない) です。サーバー側検証には order.Info.Apple?.jwsRepresentation を使用してください

タングルデータは、Unity Editorの Services > In-App Purchasing > Receipt Validation Obfuscator から生成します。

エンタイトルメント確認

Order を持っておらず、特定の製品のステータスを知りたい場合に使用します(v4の product.hasReceipt を置き換えます)。既に Order を持っている場合は、代わりにそのタイプを確認してください: PendingOrder は EntitledUntilConsumed(消費型)または EntitledButNotFinished(非消費型/サブスクリプション)にマッピングされ、ConfirmedOrder は FullyEntitled にマッピングされます。

store.CheckEntitlement(product) を呼び出し、store.OnCheckEntitlement を処理します。entitlement.Status == EntitlementStatus.FullyEntitled を確認します。

EntitlementStatus の値: FullyEntitled、EntitledUntilConsumed、EntitledButNotFinished、NotEntitled、Unknown。

既存の購入の取得

store.FetchPurchases() はストアから現在のすべての購入を取得します。アプリ起動時に便利です。

メソッド動作
GetPurchases()キャッシュされた購入リストを返します
FetchPurchases()ストアに現在の購入を照会し、キャッシュされたリストを上書きします

FetchPurchases() は呼び出しのたびにキャッシュされたリスト全体を置き換えます。非消費型アイテムとサブスクリプションのみが返されます。

Individual skills in this repo

This repo contains 9 individual skills — each has its own dedicated page.

unity-technologies/2d-pixel-perfect

Sets up, diagnoses, and fixes pixel perfect 2D rendering in Unity projects. Use when working on any retro-style or pixel art 2D game.

unity-technologies/audio-setup-mixers

Scans the scene and audio assets to appropriately route Audio Sources into existing Audio Mixer Groups, classifying each source by what it plays. Use when the user asks about cleaning up mixer assignments, routing audio through a mixer, or which group a sound belongs in. Creating mixers and groups, and setting volumes, are not automated — the skill inventories what exists and asks the user to add anything missing.

unity-technologies/build-live-game

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.

unity-technologies/generate-editor-search-query

Generates Unity Search / Quick Search queries and opens the Unity Search window for read-only Unity Editor asset or scene-object lookup requests. Always use when the user asks to find, search, show, locate, filter, look up, query, or list concrete assets or scene objects in the current project or scene, even if Unity Search is not named. Covers materials, textures, prefabs, scenes, scripts, shaders, GameObjects, components, Lights, Cameras, UI objects, labels, paths, references, selected or named assets, and asset types. Also use when the user explicitly mentions Unity Search, Quick Search, Search window, open Search, or asks what Unity Search query to use. Do not use for general project overview, project structure, folder-purpose summaries, gameplay/system explanations, how-to programming questions, web search, repository text search, build logs, package installation, menu or settings search, modifying results, or non-Unity filesystem search unless the user explicitly asks to use Unity Search.

unity-technologies/initialize-ai-navigation

Sets up and configures the Unity AI Navigation system — NavMesh surfaces, NavMesh agents, obstacles, links, modifiers, areas and costs. Use when creating walkable navigation meshes, adding pathfinding agents, setting up patrol routes, configuring obstacle avoidance and carving, connecting separate NavMeshes with links, coupling navigation with animation, or troubleshooting navigation issues.

unity-technologies/levelplay-unity-integration

Integrates the LevelPlay Mediation SDK via the Ads Mediation UPM package. Use when a developer asks about adding ads to a Unity game, implementing rewarded, interstitial, or banner ads, setting up ad mediation, configuring ad networks, installing or updating the Ads Mediation package, troubleshooting LevelPlay namespace errors, resolving Android gradle or iOS CocoaPods dependency issues for ads, configuring ATT or privacy settings for ad compliance, tracking impression-level revenue (ILRD), initializing the LevelPlay SDK, or setting up ad unit IDs. Also use when a developer wants to monetize their Unity game with ads, asks how to get started with LevelPlay, ads, or mediation, or needs help with any part of the LevelPlay integration workflow including platform-specific setup for iOS or Android. Also use when upgrading the LevelPlay or IronSource SDK version, migrating from deprecated IronSource.Agent APIs, or migrating a game from Unity Ads to LevelPlay.

unity-technologies/localization

Sets up and configures Unity Localization, including locales, String/Asset Tables, CJK font support, and Addressables workflows. Use when the user wants to add languages to a project, translate UI text, support Asian (CJK) languages with TMP fonts, or mentions i18n, l10n, multilingual support, or making a game support multiple languages.

unity-technologies/manage-sprite-atlas

Manage SpriteAtlas using prebuild pipeline with IPreprocessBuildWithReport (DEFAULT approach). Use it to configure master atlases, variant atlases, texture settings, packing settings, and platform-specific configurations. Use when the user asks about creating sprite atlases, optimizing sprites, configuring atlas settings, adding sprites to atlases, creating variant atlases, implementing automated atlas generation, or runtime sprite atlas access. Always use prebuild approach unless user explicitly requests manual authoring.

unity-technologies/migrate-birp-to-urp

Plans, executes, and troubleshoots Unity projects moving from the Built-in Render Pipeline (BiRP/BIRP/Built-in RP) to the Universal Render Pipeline (URP). Use when the user asks to upgrade, convert, switch, or migrate a project, scene, material, or shader to URP/Universal Render Pipeline; fix pink or magenta materials after URP; convert Built-in materials/shaders; move a 2D project to URP 2D; review lighting, quality, post-processing, baked lightmaps, or reflection probes after URP; or diagnose visual problems after a render-pipeline migration.

関連スキル