Esempio n. 1
0
    public Popup_Offer Setup(GlobalConfig.Data.Shop.Package pack, System.Action <bool> onClose = null)
    {
        onCloseFunc = onClose;

        if (pack != null)
        {
            presenter.Setup(pack.sku, success =>
            {
                PurchaseOffer.SetPurchaseResult(success);
                if (success)
                {
                    Exit(true);
                }
            });
        }
        else
        {
            Exit(false);
        }

        return(this);
    }
Esempio n. 2
0
    // Use this for initialization
    private IEnumerator Start()
    {
        PurchaseOffer.Setup(
            GlobalConfig.Offers.startIndex,
            GlobalConfig.Shop.offers.Count,
            GlobalConfig.Offers.firstDelay,
            GlobalConfig.Offers.offerDuration,
            GlobalConfig.Offers.coolTime,
            GlobalConfig.Offers.minResource,
            GlobalConfig.Offers.resourceTime,
            GlobalConfig.Offers.lastPurchaseTime);

#if UNITY_EDITOR
        PurchaseOffer.Setup(1, GlobalConfig.Shop.offers.Count, 10, 15, 10, 99999999, 5, 60);
#endif

        pack = Game.GetOfferPackage();
        if (pack != null)
        {
            PopupQueue.Add(0.5f, () => Game.Instance.OpenPopup <Popup_Offer>().Setup(pack));
        }

        button.onClick.AddListener(() => Game.Instance.OpenPopup <Popup_Offer>().Setup(pack));

        var wait = new WaitForSeconds(1);
        while (true)
        {
            pack = Game.GetOfferPackage();
            if (pack != null)
            {
                discountLabel.SetFormatedText(pack.discount);
                timeLabel.SetText(Utilities.TimeToString(PurchaseOffer.RemainedTime, 0));
            }
            presenter.SetActive(pack != null && pack.discount > 0);

            yield return(wait);
        }
    }
Esempio n. 3
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);
    }