protected override void GameSetup() { PaymentProductCoins[] coins = new PaymentProductCoins[6]; coins[0] = new PaymentProductCoins { Price = 0.99m, Currency = "USD", Coins = 1500, NoAds = 0, EventCode = "IAP_BunchofCoins", Description = LocaliseText.Get("Payment.BunchOfCoins"), LanguageKey = "Payment.BunchOfCoins", Product = new PaymentProduct { Name = "com.wordfarm.iap.BunchOfCoins", ProductType = ProductType.Consumable } }; coins[1] = new PaymentProductCoins { Price = 4.99m, Currency = "USD", Coins = 8700, NoAds = 0, EventCode = "IAP_BagofCoins", Description = LocaliseText.Get("Payment.BagOfCoins"), LanguageKey = "Payment.BagOfCoins", Product = new PaymentProduct { Name = "com.wordfarm.iap.BagOfCoins", ProductType = ProductType.Consumable } }; coins[2] = new PaymentProductCoins { Price = 7.99m, Currency = "USD", Coins = 17500, NoAds = 0, EventCode = "IAP_SackofCoins", Description = LocaliseText.Get("Payment.SackOfCoins"), LanguageKey = "Payment.SackOfCoins", Product = new PaymentProduct { Name = "com.wordfarm.iap.SackOfCoins", ProductType = ProductType.Consumable } }; coins[3] = new PaymentProductCoins { Price = 11.99m, Currency = "USD", Coins = 38900, NoAds = 0, EventCode = "IAP_PotofCoins", Description = LocaliseText.Get("Payment.PotOfCoins"), LanguageKey = "Payment.PotOfCoins", Product = new PaymentProduct { Name = "com.wordfarm.iap.PotOfCoins", ProductType = ProductType.Consumable } }; coins[4] = new PaymentProductCoins { Price = 16.99m, Currency = "USD", Coins = 60000, NoAds = 0, EventCode = "IAP_ChestofCoins", Description = LocaliseText.Get("Payment.ChestOfCoins"), LanguageKey = "Payment.ChestOfCoins", Product = new PaymentProduct { Name = "com.wordfarm.iap.ChestOfCoins", ProductType = ProductType.Consumable } }; coins[5] = new PaymentProductCoins { Price = 1.99m, Currency = "USD", Coins = 0, NoAds = 1, EventCode = "IAP_NoAds", Description = LocaliseText.Get("Payment.NoAds"), LanguageKey = "Payment.NoAds", Product = new PaymentProduct { Name = "com.wordfarm.iap.noads", ProductType = ProductType.NonConsumable } }; CustomPaymentManager.Coins = coins; Products = new PaymentProduct[coins.Length]; for (int i = 0; i < coins.Length; i++) { #if UNITY_ANDROID coins[i].Product.Name = coins[i].Product.Name.ToLower(); // android play store allow only lowercase #endif Products[i] = coins[i].Product; } // Initialise purchasing if (InitOnAwake) { InitializePurchasing(); } GameManager.SafeAddListener <ItemPurchasedMessage> (ItemPurchasedHandler); GameManager.SafeAddListener <LocalisationChangedMessage>(LocalisationHandler); validator = new CrossPlatformValidator(GooglePlayTangle.Data(), AppleTangle.Data(), UnityChannelTangle.Data(), Application.identifier); }
void Start() { items = GameObjectUtils.GetChildWithNameGameObject(ItemsContainer, "BuyItem", true); PaymentProductCoins[] Coins = CustomPaymentManager.Coins; for (int i = 0; i < items.Length; i++) { GameObject item = items [i]; if (i >= Coins.Length) { item.SetActive(false); continue; } PaymentProductCoins coin = Coins [i]; CustomPaymentManager payment = CustomPaymentManager.Instance as CustomPaymentManager; Product product = payment.Product(coin.Product.Name); Text price = GameObjectHelper.GetChildNamedGameObject(item, "Price", true).GetComponent <Text>() as Text; if (product != null) { price.text = product.metadata.localizedPriceString; } else { price.text = string.Format("{0} {1}", coin.Currency, coin.Price); } Text title = GameObjectHelper.GetChildNamedGameObject(item, "Name", true).GetComponent <Text> () as Text; if (coin.Coins > 0) { title.text = coin.Coins.ToString(); } else { title.gameObject.SetActive(false); } Text descr = GameObjectHelper.GetChildNamedGameObject(item, "Description", true).GetComponent <Text>() as Text; descr.text = coin.Description; if (coin.Coins == 0) { descr.gameObject.SetActive(true); } } Show(); }
public void BuyCoins(int index) { PaymentProductCoins[] Coins = CustomPaymentManager.Coins; if (index >= Coins.Length) { return; } PaymentProductCoins coin = Coins [index]; if (Debug.isDebugBuild) { GameManager.SafeQueueMessage(new ItemPurchasedMessage(coin.Product.Name)); } else { ((CustomPaymentManager)CustomPaymentManager.Instance).BuyProductId(coin.Product.Name); } }