Exemple #1
0
 public void SetData(int goodsID)
 {
     mTable     = TableShop.Get(goodsID);
     title.text = LT.Get(mTable.nameID);
     icon.SetSprite(mTable.image);
     price.text = LT.Get(mTable.priceID);
     extraObj.SetActive(mTable.extra > 0);
     extra.text = $"+{mTable.extra}";
 }
Exemple #2
0
        /// <summary>
        /// Called when a purchase completes.
        ///
        /// May be called at any time after OnInitialized().
        /// </summary>
        public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs e)
        {
            bool validPurchase = true; // Presume valid for platforms with no R.V.

            System.DateTime purchaseData = System.DateTime.Now;

            // Unity IAP's validation logic is only included on these platforms.
#if !UNITY_EDITOR && (UNITY_ANDROID || UNITY_IOS)
            // Prepare the validator with the secrets we prepared in the Editor
            // obfuscation window.
            purchaseData = System.DateTime.MinValue;
            var validator = new CrossPlatformValidator(GooglePlayTangle.Data(),
                                                       AppleTangle.Data(), Application.identifier);

            try
            {
                // On Google Play, result has a single product ID.
                // On Apple stores, receipts contain multiple products.
                var result = validator.Validate(e.purchasedProduct.receipt);
                // For informational purposes, we list the receipt(s)
                //Debug.Log("Receipt is valid. Contents:");
                foreach (IPurchaseReceipt productReceipt in result)
                {
                    if (purchaseData.Ticks < productReceipt.purchaseDate.Ticks)
                    {
                        purchaseData = productReceipt.purchaseDate;
                    }
                }
            }
            catch (IAPSecurityException ex)
            {
                Debug.LogError("Invalid receipt:" + ex.Message);
                validPurchase = false;
            }
#endif

            if (validPurchase)
            {
                var pid   = e.purchasedProduct.definition.id;
                var goods = TableShop.Get(a => a.productID == pid);
                D.I.OnPurchaseSuccess(goods.id, purchaseData);
            }
            else
            {
                Toast.Show("Purchase Failed, Invalid receipt.");
            }
            return(PurchaseProcessingResult.Complete);
        }
        public void OnPurchaseSuccess(int shopGoodsID, DateTime date)
        {
            var t = TableShop.Get(shopGoodsID);

            if (t.type == 0) // Consumable
            {
                AddDiamondWithEffect(t.diamonds + t.extra);
                SaveLocalData();
                DispatchEvent(EventGameData.Action.DataChange);
            }
            else if (t.type == 2) // Subscription
            {
                localData.lastVipTicks = date.Ticks;
                SaveLocalData();
                DispatchEvent(EventGameData.Action.DataChange);
            }
        }
 public void Purchase(int shopGoodsID)
 {
     var t = TableShop.Get(shopGoodsID);
     // IAPManager.Instance.Purchase(t.productID);
 }