using System;
using UnityEngine.Events;
using UnityEngine.UI;
namespace UnityEngine.Purchasing
{
///
/// A GUI component for exposing the current price and allow purchasing of In-App Purchases. Exposes configurable
/// elements through the Inspector.
///
///
[Obsolete("IAPButton is deprecated, please use CodelessIAPButton instead.", false)]
[RequireComponent(typeof(Button))]
[AddComponentMenu("In-App Purchasing/IAP Button (legacy)", int.MaxValue)]
[HelpURL("https://docs.unity3d.com/Manual/UnityIAP.html")]
public class IAPButton : BaseIAPButton
{
///
/// The type of this button, can be either a purchase or a restore button.
///
public enum ButtonType
{
///
/// This button will display localized product title and price. Clicking will trigger a purchase.
///
Purchase,
///
/// This button will display a static string for restoring previously purchased non-consumable
/// and subscriptions. Clicking will trigger this restoration process, on supported app stores.
///
Restore
}
///
/// Type of event fired after a successful purchase of a product.
///
[Serializable]
public class OnPurchaseCompletedEvent : UnityEvent
{
}
///
/// Type of event fired after a failed purchase of a product.
///
[Serializable]
public class OnPurchaseFailedEvent : UnityEvent
{
}
///
/// Type of event fired after a restore transactions was completed.
///
[Serializable]
public class OnTransactionsRestoredEvent : UnityEvent
{
}
///
/// Which product identifier to represent. Note this is not a store-specific identifier.
///
[HideInInspector]
public string productId = "";
///
/// The type of this button, can be either a purchase or a restore button.
///
[Tooltip("The type of this button, can be either a purchase or a restore button.")]
public ButtonType buttonType = ButtonType.Purchase;
///
/// Consume the product immediately after a successful purchase.
///
[Tooltip("Consume the product immediately after a successful purchase.")]
public bool consumePurchase = true;
///
/// Event fired after a restore transactions.
///
[Tooltip("Event fired after a restore transactions.")]
public OnTransactionsRestoredEvent onTransactionsRestored = null;
///
/// Event fired after a successful purchase of this product.
///
[Tooltip("Event fired after a successful purchase of this product.")]
public OnPurchaseCompletedEvent onPurchaseComplete = null;
///
/// Event fired after a failed purchase of this product.
///
[Tooltip("Event fired after a failed purchase of this product.")]
public OnPurchaseFailedEvent onPurchaseFailed = null;
///
/// Displays the localized title from the app store.
///
[Tooltip("[Optional] Displays the localized title from the app store.")]
public Text titleText;
///
/// Displays the localized description from the app store.
///
[Tooltip("[Optional] Displays the localized description from the app store.")]
public Text descriptionText;
///
/// Displays the localized price from the app store.
///
[Tooltip("[Optional] Displays the localized price from the app store.")]
public Text priceText;
internal override string GetProductId()
{
return productId;
}
internal override bool IsAPurchaseButton()
{
return buttonType == ButtonType.Purchase;
}
protected override bool IsARestoreButton()
{
return buttonType == ButtonType.Restore;
}
protected override bool ShouldConsumePurchase()
{
return consumePurchase;
}
protected override void OnTransactionsRestored(bool success, string error)
{
onTransactionsRestored?.Invoke(success, error);
}
protected override void OnPurchaseComplete(Product purchasedProduct)
{
onPurchaseComplete?.Invoke(purchasedProduct);
}
///
/// Invoked on a failed purchase of the product associated with this button
///
/// The which failed to purchase
/// Information to help developers recover from this failure
public void OnPurchaseFailed(Product product, PurchaseFailureReason reason)
{
onPurchaseFailed?.Invoke(product, reason);
}
protected override Button GetPurchaseButton()
{
return GetComponent