listener | 负责处理购买相关事件的应用程序的监听器。 |
builder | Unity IAP 配置。 |
使用指定的监听器和配置初始化 Unity IAP。
下面是针对示例商店类初始化 Unity IAP 的示例。
using UnityEngine;
using UnityEngine.Purchasing;
public class MyStoreClass : MonoBehaviour, IStoreListener
{
void Awake()
{
ConfigurationBuilder builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
builder.AddProduct("levelpackfoo", ProductType.NonConsumable);
UnityPurchasing.Initialize(this, builder);
}
public void OnInitialized(IStoreController controller, IExtensionProvider extensions) {}
public void OnInitializeFailed(InitializationFailureReason error) {}
public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs e) { return PurchaseProcessingResult.Complete; }
public void OnPurchaseFailed(Product item, PurchaseFailureReason r) {}
}