Example #1
0
    public void OnItemClick(int index)
    {
        var item = gameManager.shopItems[index];

        if (item == null)
        {
            return;
        }

        PurchaseSystem.Purchase(PurchaseProvider.Bazaar, item.sku, (success, msg) =>
        {
            if (success)
            {
                purchaseditem = item;
                PurchaseSystem.Consume();
                StartCoroutine(AddGold(item.gold));
#if DATABEEN
                DataBeen.SendPurchaseData(item.sku, msg);
#endif
            }
        });
    }
Example #2
0
    public UiShopItem Setup(string sku, System.Action <bool> onClick = null)
    {
        pack = GlobalConfig.Shop.GetPackage(sku);
        if (pack == null)
        {
            return(this);
        }

        images.SetActiveChild(pack.image);
        if (title)
        {
            title.SetText(pack.title);
        }
        if (gemsLabel)
        {
            gemsLabel.SetFormatedText(pack.gems);
        }
        if (bombLabel)
        {
            bombLabel.SetFormatedText(pack.bombs);
        }
        if (hammerLabel)
        {
            hammerLabel.SetFormatedText(pack.hammers);
        }
        if (missileLabel)
        {
            missileLabel.SetFormatedText(pack.missiles);
        }
        if (priceLabel)
        {
            priceLabel.SetFormatedText(pack.price);
        }
        if (lastPriceLabel)
        {
            lastPriceLabel.SetFormatedText(pack.lastPrice);
        }
        if (discountLabel)
        {
            if (pack.discount > 0)
            {
                discountLabel.SetFormatedText(pack.discount);
            }
            else
            {
                discountLabel.transform.parent.gameObject.SetActive(false);
            }
        }

        button.onClick.AddListener(() =>
        {
            button.SetInteractable(false);
            PurchaseSystem.Purchase(PurchaseProvider.Market, sku, (succeed, token) =>
            {
                if (succeed)
                {
                    Purchased(sku, token, () => onClick?.Invoke(true));
                }
                else
                {
                    onClick?.Invoke(false);
                }

                button.SetInteractable(true);
            });
        });

        return(this);
    }