/// <summary>Initialises the Subscription Window with all required parameters.</summary> /// <param name="productIDs">The list of product IDs available for this application.</param> /// <param name="backgroundSprite">The sprite to set for the background image. It must be a 16:9 image.</param> /// <param name="foregroundSprite">The sprite to set for the foreground image. It must be a 16:9 image with transparency (Or it will hide the background.)</param> /// <param name="termsLinkText">The text to put on the Terms & Conditions link.</param> /// <param name="restoreLinkText">The text to put on the Restore Purchases link.</param> /// <param name="encouragementText">The text to use to encourage the user to subscribe.</param> /// <param name="priceTextFormat">The format string to use for the price. Must contain %s where the actual price string will be placed.</param> /// <param name="subscribeButtonSprite">The sprite to set for the subscription button image.</param> /// <param name="subscribeButtonText">The text to use for the subscription button text.</param>\ /// <remarks>The window title, description and actual price is derived from the product IDs.</remarks> public void Initialise(ProductIDs productIDs, Sprite backgroundSprite = null, Sprite foregroundSprite = null, string termsLinkText = "Terms & Conditions", string restoreLinkText = "Restore Purchases", string encouragementText = "Buy Now!", string priceTextFormat = "Only %s/month", Sprite subscribeButtonSprite = null, string subscribeButtonText = "Subscribe Now") { void OpenWindow() { SubscriptionWindow.Instance.titleTMP.text = AppCentralStoreListener.LocalizedTitle; SubscriptionWindow.Instance.descriptionTMP.text = AppCentralStoreListener.LocalizedDescription; SubscriptionWindow.Instance.priceTMP.text = string.Format(priceTextFormat, AppCentralStoreListener.LocalizedPriceString); SubscriptionWindow.Instance.gameObject.SetActive(true); } if (AppCentralStoreListener.IsUserSubscribed()) { Debug.Log("User already subscribed, not showing paywall"); return; } AnalyticsCommunicator.SendApplicationStartRequest(); Color transparent = new Color(1f, 1f, 1f, 0f); this.backgroundImage.sprite = backgroundSprite; if (backgroundSprite == null) { this.backgroundImage.color = transparent; } this.foregroundImage.sprite = foregroundSprite; if (foregroundSprite == null) { this.foregroundImage.color = transparent; } this.termsLinkTMP.text = termsLinkText; this.restoreLinkTMP.text = restoreLinkText; this.encouragementTitleTMP.text = encouragementText; this.subscribeButtonImage.sprite = subscribeButtonSprite; if (subscribeButtonSprite == null) { this.subscribeButtonImage.color = transparent; } this.subscribeButtonTMP.text = subscribeButtonText; SubscriptionWindow.Instance.storeListener = new AppCentralStoreListener(productIDs, OpenWindow); }
/// <summary>Entry point: How the whole system starts.</summary> /// <param name="productIDs">Product IDs for what can be bought in the game.</param> /// <param name="onInitialisedAction">The action to call when this is initialised.</param> public AppCentralStoreListener(ProductIDs productIDs, OnInitialisedDelegate onInitialisedAction) { if (AppCentralStoreListener.IsInitialized()) { return; } Debug.Log("Init Subscription " + productIDs.subscriptionProductID); AppCentralStoreListener.productNameAppleSubscription = productIDs.subscriptionProductID; AppCentralStoreListener.productIDSubscription = productIDs.subscriptionProductID; this.OnInitialisedEvent += onInitialisedAction; // Create a builder, first passing in a suite of Unity provided stores. ConfigurationBuilder purchasingConfiguration = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance()); List <ProductDefinition> productDefinitions = new List <ProductDefinition> { new ProductDefinition(AppCentralStoreListener.ProductIDConsumable, UnityEngine.Purchasing.ProductType.Consumable), new ProductDefinition(AppCentralStoreListener.ProductIDNonConsumable, UnityEngine.Purchasing.ProductType.NonConsumable), }; purchasingConfiguration.AddProducts(productDefinitions); // Adding the subscription product. // Notice this uses store-specific IDs, illustrating if the Product ID was configured differently between Apple and Google stores. // Also note that one uses the general ProductIDSubscription handle inside the game - the store-specific IDs must only be referenced here. purchasingConfiguration.AddProduct(AppCentralStoreListener.productIDSubscription, UnityEngine.Purchasing.ProductType.Subscription, new IDs { { AppCentralStoreListener.productNameAppleSubscription, AppleAppStore.Name }, { AppCentralStoreListener.productNameGoogleSubscription, GooglePlay.Name }, }); // Kick off the remainder of the set-up with an asynchrounous call, passing the configuration // and this class' instance. Expect a response either in OnInitialized or OnInitializeFailed. UnityPurchasing.Initialize(this, purchasingConfiguration); }