Note: Screenshots and menu choices might differ between release versions.
本文档解释如何激活应用内购 (IAP)。
Unity IAP 包提供了编码和无编码方法,您可以设置为: - 允许用户在您的游戏中购买物品。 - 连接到商店,以便您可以从这些购买中获得收入。
以下是这些步骤的概述:
定义该游戏的应用内购策略。
将您的项目设置为 Unity 服务。
激活 IAP 以自动安装软件包。
配置设置。
创建和编目您想要出售的游戏内物品。
Use the Codeless IAP button to give users a way to buy items. Then, once you have the logic working, consider customizing the button look and feel. Or use the scripted IAP for a rich API to enhance this process.
将您的应用连接到相关的应用商店,例如 Google、Apple 或 Android。
将物品添加到商店。
综述:
You can also do many of these steps, or fine-tune what you create, with the In-App Purchasing API.
Note: Versions of Unity IAP between 4.2.0 and 4.6.0 automatically install Unity Analytics. Unity Analytics is a paid service, and if your usage exceeds the free tier limits, you will be responsible for paying for your usage. To avoid using Unity Analytics, install Unity IAP 4.7.0 or later, and/or remove Unity Analytics from your project (which you can learn more about here).
Note: The Samsung Galaxy store is now obsolete and is no longer supported in the Unity In-App Purchasing package 4.0.0 and later. This guide to configure the Samsung Galaxy store only applies to the IAP package version 3.1.0 and earlier. If you are using the Unity IAP package 4.0.0 and later and you want to implement a Samsung Galaxy store, use the Unity Distribution Platform instead.
在 Unity 编辑器中打开您的 Unity 项目。
选择 Window\General\Services。将出现 Services 窗口。
创建一个项目 ID,然后将该项目连接到一个组织。
回答 COPPA 合规性问题。
Services 窗口将显示服务列表。单击 In-App Purchasing。
将出现 Project Settings 窗口。
Activate the toggle next to In-App Purchasing Settings to ON.
This automatically installs the IAP package from the package manager, providing you with new features and menu items to help you manage IAP.
您的任务是创建供玩家购买的物品并获取其标识。
You must tie product identifiers (strings) to each item you are selling by using a specified format. Some stores require that you customize the Product ID for their stores.
Refer to the Unity Learn IAP classes.
从 Unity IAP 版本 2.x 升级到未来版本的重要说明。
If you are updating from Unity IAP (com.unity.purchasing + the Asset Store plugin) versions 2.x to future versions, to resolve compilation errors, complete the following actions:
IAPProductCatalog.json
和 BillingMode.json
从 Assets/Plugins/UnityPurchasing/Resources/
移动到 Assets/Resources/
AppleTangle.cs
和 GooglePlayTangle.cs
从:’Assets/Plugins/UnityPurchasing/generated’ 移动到:Assets/Scripts/UnityPurchasing/generated
。Assets/Plugins/UnityPurchasing
中的文件。The following error messages might indicate that Unity IAP is deactivated in the Unity Cloud Services window, or that Unity is disconnected from the Internet:
* CS0246
* System.Reflection.ReflectionTypeLoadException
* UnityPurchasing/Bin/Stores.dll
* UnityEngine.Purchasing
要解决这些错误,请执行以下操作:
Reload the Services window by closing, then reopening it. After reloading, ensure that the Unity IAP service is active. If this doesn’t work, try to disconnect and reconnect to the Internet, then sign back into Unity Services and re-activate Unity IAP.
注意:您必须是项目的所有者 (Owner) 或管理员 (Manager) 角色。