IAP定义产品 Defining products

为了使用应用内购买,您的应用必须提供待售产品列表。您可以通过脚本或使用无代码 IAP 目录Window >统一内购 IAP目录)。无论使用哪种实现方式,都必须为每个产品定义适当的属性。本页详细介绍了这些属性。
IAP定义产品  Defining products
Unity 编辑器中的IAP 目录GUI

产品编号

输入一个跨平台唯一标识符作为产品在与应用商店通信时的默认 ID。 重要提示:ID 只能包含小写字母、数字、下划线或句点。

产品类别

每个产品必须属于以下类型之一:
类型 描述 例子
耗材 用户可以重复购买产品。消耗品无法恢复。 * 虚拟货币 * 健康药水 * 临时能量提升。
非消耗品 用户只能购买产品一次。可以恢复非消耗品。 * 武器或盔甲 * 获得额外内容
订阅 用户可以在有限的时间内访问产品。订阅产品可以恢复。 * 每月访问在线游戏 * VIP 身份授予每日奖金 * 免费试用
注意:有关订阅类型支持的更多信息,请参阅订阅产品支持部分。

先进的

此部分定义与您的产品相关联的元数据,以供在游戏内商店中使用。

说明

使用以下字段为您的产品添加描述性文本:
场地 数据类型 描述 例子
产品区域 枚举 确定您所在地区可用的应用程序商店。 英语(美国)(Google Play、Apple)
产品名称 细绳 您的产品在应用商店中显示的名称。 “健康药水”
产品描述 细绳 您的产品出现在应用程序商店中时的描述性文本,通常是对产品内容的解释。 “恢复 50 HP。”
通过单击加号 ( + ) 图标并选择其他语言环境,为标题描述字段添加翻译。您可以根据需要添加任意数量的翻译。
IAP定义产品  Defining products
在IAP 目录GUI中填充产品的描述字段

支出

使用此部分为您支付给购买者的内容添加本地固定定义。支出使管理游戏内钱包或库存变得更加容易。通过使用名称和数量标记产品,开发人员可以在购买时快速调整游戏中某些项目类型(例如,硬币或宝石)的数量。 注意:此功能仅适用于 Unity 2017.2 或更高版本。
场地 数据类型 描述 例子
支付类型 枚举 定义购买者收到的内容类别。有四种可能的类型。 * 货币 * 物品 * 资源 * 其他
支付子类型 细绳 为内容类别提供粒度级别。 *货币类型的“Gold”和“Silver”子类型 * Item 类型的“Potion”和“Boost”子类型
数量 诠释 指定购买者在付款中收到的商品数量、货币等。 * 1 * >25 * 100
数据 以您喜欢的任何方式使用此字段作为在代码中引用的属性。 * UI 元素的标志 * 物品稀有度
IAP定义产品  Defining products
在IAP 目录GUI中填充产品的付款字段
注意:您可以向单个产品添加多个付款。 有关 PayoutDefinition 类的更多信息,请参阅脚本参考。您始终可以使用此类在脚本中将支付信息添加到产品。例如:
using UnityEngine.Purchasing;

new PayoutDefinition (PayoutType.Currency, "Gold", 100)
请注意,IAP 目录充当产品目录字典,而不是库存管理器。您仍然必须实施处理购买内容传输的代码。

商店 ID 覆盖

默认情况下,Unity IAP 假定您的产品在所有应用商店中具有相同的标识符(在上面的ID字段中指定)。Unity 建议尽可能这样做。但是,有些情况下这是不可能的,例如同时发布到iOS 和 Mac 商店,禁止开发人员在两者之间使用相同的产品 ID。 在这些情况下,使用覆盖字段来指定产品的正确标识符(与跨平台 ID 不同的地方)。 您也可以通过编程方式执行此操作,如下所示:
using UnityEngine;
using UnityEngine.Purchasing;

public class MyIAPManager {
    public MyIAPManager () {
        var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
        builder.AddProduct("100_gold_coins", ProductType.Consumable, new IDs
        {
            {"100_gold_coins_google", GooglePlay.Name},
            {"100_gold_coins_mac", MacAppStore.Name}
        });
        // Initialize Unity IAP...
    }
}
在此示例中,产品在 Google Play 中标识为“100_gold_coins_google”,在 Apple App Store 中标识为“100_gold_coins_mac”。 注意:覆盖仅更改 Unity IAP 在与应用商店通信时使用的标识符。在进行 API 调用时,您仍应使用产品的跨平台标识符。 重要提示:ID 只能包含小写字母、数字、下划线或句点。

Google 配置(Google Play 导出需要)

为在 Google Play 中创建的定价模板提供产品价格或 ID 。
IAP定义产品  Defining products
在IAP 目录GUI中填充产品的Google 配置字段。

Apple 配置(Apple 导出需要)

从下拉菜单中选择定价层。Unity 支持预定义的 Apple 价格点,但不支持任意值。 选择要上传的屏幕截图。 有关屏幕截图规范的信息,请参阅 Apple 的发布者支持文档。
IAP定义产品  Defining products
在IAP 目录GUI中填充产品的Apple 配置字段。

在脚本中定义产品

您还可以使用Purchasing Configuration Builder以编程方式声明您的产品列表。您必须为每个产品提供唯一的跨商店产品 ID产品类型
using UnityEngine;
using UnityEngine.Purchasing;

public class MyIAPManager {
    public MyIAPManager () {
        var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
        builder.AddProduct("100_gold_coins", ProductType.Consumable);
        // Initialize Unity IAP...
    }
}
 

Defining products

In order to use in-app purchases, your app must provide a list of Products for sale. You can do this through scripting, or using the Codeless IAP Catalog (Window > Unity IAP  > IAP Catalog). Whichever implementation you use, you must define the appropriate attributes for each Product. This page covers these attributes in detail.
IAP定义产品  Defining products
The IAP Catalog GUI in the Unity Editor

Product ID

Enter a cross-platform unique identifier to serve as the Product’s default ID when communicating with an app store. Important: The ID may only contain lowercase letters, numbers, underscores, or periods.

Product Type

Each Product must be of one of the following Types:
Type Description Examples
Consumable Users can purchase the Product repeatedly. Consumable Products cannot be restored. * Virtual currencies * Health potions * Temporary power-ups.
Non-Consumable Users can only purchased the Product once. Non-Consumable Products can be restored. * Weapons or armor * Access to extra content
Subscription Users can access the Product for a finite period of time. Subscription Products can be restored. * Monthly access to an online game * VIP status granting daily bonuses * A free trial
Note: For more information on Subscription type support, see the section on Subscription Product support.

Advanced

This section defines the metadata associated with your Product for use in an in-game store.

Descriptions

Use the following fields to add descriptive text for your Product:
Field Data type Description Example
Product Locale Enum Determines the app stores available in your region. English (U.S.) (Google Play, Apple)
Product Title String The name of your Product as it appears in an app store. “Health Potion”
Product Description String The descriptive text for your Product as it appears in an app store, usually an explanation of what the Product is. “Restores 50 HP.”
Add Translations for the Title and Description fields by clicking the plus (+) icon and selecting an additional locale. You can add as many translations as you like.
IAP定义产品  Defining products
Populating Descriptions fields for Products in the IAP Catalog GUI

Payouts

Use this section to add local, fixed definitions for the content you pay out to the purchaser. Payouts make it easier to manage in-game wallets or inventories. By labeling a Product with a name and quantity, developers can quickly adjust in-game counts of certain item types upon purchase (for example, coins or gems). Note: This functionality is only available in Unity 2017.2 or higher.
Field Data type Description Example
Payout Type Enum Defines the category of content the purchaser receives. There are four possible Types. * Currency * Item * Resource * Other
Payout Subtype String Provides a level of granularity to the content category. * “Gold” and “Silver” subtypes of a Currency type * “Potion” and “Boost” subtypes of an Item type
Quantity Int Specifies the number of items, currency, and so on, that the purchaser receives in the payout. * 1 * >25 * 100
Data Use this field any way you like as a property to reference in code. * Flag for a UI element * Item rarity
IAP定义产品  Defining products
Populating Payouts fields for Products in the IAP Catalog GUI
Note: You can add multiple Payouts to a single Product. For more information on the PayoutDefinition class, see the Scripting Reference. You can always add Payout information to a Product in a script using this class. For example:
using UnityEngine.Purchasing;

new PayoutDefinition (PayoutType.Currency, "Gold", 100)
Note that the IAP Catalog acts as a Product catalog dictionary, not as an inventory manager. You must still implement the code that handles conveyance of the purchased content.

Store ID Overrides

By default, Unity IAP assumes that your Product has the same identifier (specified in the ID field, above) across all app stores. Unity recommends doing this where possible. However, there are occasions when this is not possible, such as when publishing to both iOS  and Mac stores, which prohibit developers from using the same product ID across both. In these cases, use the override fields to specify the Product’s correct identifier where it differs from the cross-platform ID. You can also do this programmatically, as follows:
using UnityEngine;
using UnityEngine.Purchasing;

public class MyIAPManager {
    public MyIAPManager () {
        var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
        builder.AddProduct("100_gold_coins", ProductType.Consumable, new IDs
        {
            {"100_gold_coins_google", GooglePlay.Name},
            {"100_gold_coins_mac", MacAppStore.Name}
        });
        // Initialize Unity IAP...
    }
}
In this example, the Product identifies as “100_gold_coins_google” to Google Play and “100_gold_coins_mac” to the Apple App Store. Note: Overrides only change the identifier Unity IAP uses when communicating with app stores. You should still use the Product’s cross-platform identifier when making API calls. Important: The ID may only contain lowercase letters, numbers, underscores, or periods.

Google Configuration (required for Google Play export)

Provide either a Product price, or an ID for a Pricing Template created in Google Play.
IAP定义产品  Defining products
Populating Google Configuration fields for Products in the IAP Catalog GUI.

Apple Configuration (required for Apple export)

Select a Pricing Tier from the dropdown menu. Unity supports predefined Apple price points, but not arbitrary values. Select a screenshot to upload. For information on screenshot specs, see Apple’s publisher support documentation.
IAP定义产品  Defining products
Populating Apple Configuration fields for Products in the IAP Catalog GUI.

Defining Products in scripts

You can also declare your Product list programmatically using the Purchasing Configuration Builder. You must provide a unique cross-store Product ID and Product Type for each Product:
using UnityEngine;
using UnityEngine.Purchasing;

public class MyIAPManager {
    public MyIAPManager () {
        var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
        builder.AddProduct("100_gold_coins", ProductType.Consumable);
        // Initialize Unity IAP...
    }
}