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. /// /// [RequireComponent(typeof(Button))] [AddComponentMenu("In-App Purchasing/IAP Button")] [HelpURL("https://docs.unity3d.com/Manual/UnityIAP.html")] public class IAPButton : MonoBehaviour { /// /// 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. /// [System.Serializable] public class OnPurchaseCompletedEvent : UnityEvent { }; /// /// Type of event fired after a failed purchase of a product. /// [System.Serializable] public class OnPurchaseFailedEvent : 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 successful purchase of this product. /// [Tooltip("Event fired after a successful purchase of this product.")] public OnPurchaseCompletedEvent onPurchaseComplete; /// /// Event fired after a failed purchase of this product. /// [Tooltip("Event fired after a failed purchase of this product.")] public OnPurchaseFailedEvent onPurchaseFailed; /// /// 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; void Start() { Button button = GetComponent