本指南介绍如何建立 Unity 游戏与应用内购 (IAP) 商店进行交互所需的数字记录和关系。本指南针对的是 Unity IAP 购买 API。
应用内购 (IAP) 是通过资金交易购买数字商品的过程。一个平台的应用商店会允许购买代表数字商品的产品。这些商品有一个标识符(通常是字符串数据类型)。商品的类型 (Types) 可表示其耐用性:_订阅、消耗品_(可以多次购买)以及_非消耗品_(可以购买一次)是最常见的类型。
Write a game implementing Unity IAP. See Unity IAP Initialization and the Sample IAP Project.
准备好游戏的商品标识符以便稍后在 Google Play Developer Console(开发者控制台)中使用。
Build a signed non-Development Build Android APK from your game.
提示:务必妥善保存您的密钥库文件。始终需要原始密钥库来更新已发布的 Google Play 应用程序。
提示:在本地测试期间,请复用您上次上传的 APK 的 Bundle Version Code 以便允许侧载 (side-loading),无需先将已更改的 APK 上传到 Developer Console。请参阅 Android 平台 Player 设置。
通过用于发布游戏的 Google 帐户,将 Android 应用程序注册到 Google Play Developer Console。
NOTE: This guide uses the Google Play License Testing approach for testing in-app purchase integration.
Choose Create app.
Give the application an App name and select the appropriate options for your game.
Navigate to Testing/Closed testing in the left nav and choose Create track. Select your APK and upload it. Also complete the basic Dashboard requirements, upload screenshots and add a Short and Full description. You can also create an Internal test track.
Now that you have uploaded our first binary, you can add the IAP products.
Navigate to In-app Products and choose Create product.
Define the Product ID , product details and price. Remember to activate the product after saving.
您可以在 Managed product 中指定消耗品或非消耗品商品类型。Unity IAP 也支持 Subscription(订阅)商品类型。
NOTE: The “Product ID” here is the same identifier used in the game source code, added to the [Unity IAP ConfigurationBuilder] instance via AddProduct()
or AddProducts()
, like “gold50”.
Add your testers to License Testing.
Navigate to All Apps on your Google Developer dashboard.
Select Settings/License Testing. Add each Google Account email address. Save changes.
NOTE: There may be a delay of several hours from the time you publish the APK.
Note: To test updates retaining permission to purchase IAPS’s for free, you may side-load applications, updating the existing store-downladed APK install.
To test the IAP, make a purchase on a device logged in with a Tester Google Account. A modified purchase dialog box appears to confirm the fact this product is under test and is free.
WARNING: If this dialog box does not appear, then the Tester Google Account will be charged real money for the product.
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.