示例#1
0
 private void BuyUpgrade()
 {
     if (!PlayerDataManager.IsTankLocked(CurrentTank) && !PlayerDataManager.IsTankFullyUpgraded(CurrentTank))
     {
         int coinsNeededForLevelUp = PlayerDataManager.GetCoinsNeededForLevelUp(CurrentTank);
         if (PlayerDataManager.BuyTankUpgrade(CurrentTank))
         {
             MenuController.instance.StartCoroutine(AudioManager.AllUpgradedSound());
             tankFlashRoutine = StartCoroutine(TankFlash(tanks[tankIndex]));
             TankAnalytics.BoughtWithSoftCurrency("upgrade", "Upgrade for " + CurrentTank.name, coinsNeededForLevelUp);
             TankPrefs.CloudSyncComplete = true;
             PlayerDataManager.SaveToCloudOnNextInterval = true;
         }
         else if (PlayerDataManager.GetCoins() < coinsNeededForLevelUp)
         {
             MenuController.ShowMenu <OutOfCurrencyPopup>().SetCurrency(CurrencyType.Coins);
         }
         UpdateUpgradeData(flashUpgradeText: true);
     }
     else
     {
         if (PlayerDataManager.IsTankFullyUpgraded(CurrentTank))
         {
             return;
         }
         int num = Variables.instance.GetTankGemValue(CurrentTank);
         if (PlayerDataManager.HasActiveDailyOffer())
         {
             for (int i = 0; i != dailyOffers.Length; i++)
             {
                 if (dailyOffers[i] != null && dailyOffers[i].id.Equals(CurrentTank.id) && dailyOffers[i].discount > 0 && dailyOffers[i].currency == CurrencyType.Gems)
                 {
                     num = dailyOffers[i].price;
                     break;
                 }
             }
         }
         if (PlayerDataManager.TakeGems(num))
         {
             PlayerDataManager.AddTankCards(CurrentTank, 1);
             StartCoroutine(UnlockRoutine());
             tankFlashRoutine = StartCoroutine(TankFlash(tanks[tankIndex]));
             TankAnalytics.BoughtWithPremiumCurrency("tank", CurrentTank.id, num);
             TankPrefs.SaveAndSendToCloud(forced: true);
         }
         else
         {
             MenuController.ShowMenu <OutOfCurrencyPopup>().SetCurrency(CurrencyType.Gems);
         }
         UpdateUpgradeData(flashUpgradeText: true);
     }
 }
示例#2
0
    public void ProcessPurchase(string id)
    {
        Debug.Log("购买的物品ID是:" + id);
        Product iAPInfo = GetIAPInfo(id);
        bool    flag    = true;

        if (id.Contains("gems")) //宝石
        {
            // Debug.Log("Getgems 自定义数量");
            //PlayerDataManager.AddGems((int)50);
            //MenuController.UpdateTopMenu();
        }
        else if (id.Contains("tank") && id.Contains("Cards"))
        {
            PlayerDataManager.AddTankCards(id.Replace("Cards", ""), (int)50);
        }
        else if (id.Contains("coins"))
        {
            Debug.Log("Getcoins 自定义数量");
            PlayerDataManager.AddCoins((int)50);
        }
//		if (id.Contains("sub"))
//		{
//			UnityEngine.Debug.Log("Product is a subscription");
////
//		}
//		else
//		{
//			UnityEngine.Debug.Log("Product is NOT a subscription");
//		}
        if (flag)
        {
            SetSomeIAPBought();
        }
        TankPrefs.SaveAndSendToCloud(true);
        if (iapCallback != null)
        {
            iapCallback();
            iapCallback = null;
        }
        IAPTransactionInProgress = false;
    }
示例#3
0
    private IEnumerator InitIAP()
    {
        while (!iapItem.IsInitialized)
        {
            yield return(null);
        }
        gemAmountText.GetComponent <LocalizationParamsManager>().SetParameterValue("AMOUNT", iapItem.product.definition.payout.quantity.ToString());
        bool someIAPbought = IAPManager.GetSomeIAPBought();

        iapItem.SetOnComplete(delegate
        {
            TankAnalytics.BoughtNoAdsOffer(!someIAPbought);
            LeanTween.delayedCall(1.25f, (Action) delegate
            {
                AnimatedCurrencyController.AnimateGems((int)iapItem.product.definition.payout.quantity, MenuController.UICamera.WorldToViewportPoint(iapItem.transform.position), MenuController.TotalGemsPositionViewport, 1, null, delegate(int tc)
                {
                    //MenuController.instance.topTotalGemsText.Tick(tc);
                });
                AudioMap.PlayClipAt(AudioMap.instance["gemCollect"], Vector3.zero, AudioMap.instance.uiMixerGroup);
                TankPrefs.SaveAndSendToCloud(forced: true);
                MenuController.HideMenu <NoAdsPopup>();
            });
        });
    }
    public void SetValues(int i, ShopMenu.ShopItem item)
    {
        index = i;
        chestContainer.SetActive(item.type == ShopMenu.ShopItemType.Chest);
        cardContainer.SetActive(item.type == ShopMenu.ShopItemType.TankCard || item.type == ShopMenu.ShopItemType.BoosterCard);
        currencyContainer.SetActive(item.type == ShopMenu.ShopItemType.Coin || item.type == ShopMenu.ShopItemType.Gem);
        premiumCardContainer.SetActive(item.type == ShopMenu.ShopItemType.PremiumCard);
        mainButton.interactable    = !item.bought;
        graphicButton.image.sprite = (item.bought ? MenuBase <ShopMenu> .instance.buttonDisabledSprite : MenuBase <ShopMenu> .instance.buttonEnabledSprite);
        priceText.text             = item.price.ToString();
        priceText.gameObject.SetActive(!item.bought);
        purchased.SetActive(item.bought);
        ShopMenu.ShopItemType type = item.type;
        if (type == ShopMenu.ShopItemType.TankCard || type == ShopMenu.ShopItemType.PremiumCard)
        {
            Tank tank = Manager <PlayerDataManager> .instance.variables.GetTank(item.id);

            headerText.text            = ScriptLocalization.Get(tank.name);
            cardBackgroundImage.sprite = MenuController.GetMenu <ShopMenu>().GetCardBackground(item.rarity);
            premiumCardImage.sprite    = tank.bigCard;
            cardElement.SetValues(tank, item.count, useNew: false);
            cardElement.background.sprite = MenuController.GetMenu <ShopMenu>().GetCardBackground(item.rarity, small: true);
            purchaseWithGems.SetActive(item.currency == CurrencyType.Gems);
            purchaseWithCoins.SetActive(item.currency == CurrencyType.Coins);
            if (item.discount > 0 && item.type == ShopMenu.ShopItemType.PremiumCard && !item.bought)
            {
                priceContainer.SetActive(value: false);
                premiumDiscountContainer.SetActive(value: true);
                originalPriceText.text = Variables.instance.GetTankGemValue(tank).ToString();
                newPriceText.text      = item.price.ToString();
                discountText.text      = $"-{item.discount.ToString()}%";
            }
            if (item.bought)
            {
                purchaseWithCoins.SetActive(value: false);
                purchaseWithGems.SetActive(value: false);
            }
            mainButton.onClick.RemoveAllListeners();
            mainButton.onClick.AddListener(delegate
            {
                SDKManager.Instance.ShowAd(ShowAdType.ChaPing, 1, "点击每日奖励");
                ShopMenu.TryPurchase(item.price, item.currency, delegate
                {
                    PlayerDataManager.BuyDailyOffer(index);
                    mainButton.interactable    = false;
                    graphicButton.enabled      = true;
                    graphicButton.interactable = false;
                    priceText.gameObject.SetActive(value: false);
                    purchased.SetActive(value: true);
                    purchaseWithGems.SetActive(value: false);
                    purchaseWithCoins.SetActive(value: false);
                    premiumDiscountContainer.SetActive(value: false);
                    cardElement.newTextContainer.SetActive(value: false);
                    CurrencyType currency = item.currency;
                    int price             = item.price;
                    if (currency == CurrencyType.Coins)
                    {
                        MenuController.instance.topTotalCoinsText.Tick(-price);
                        cardElement.AnimateTankCardCountRoll(item);
                    }
                    else
                    {
                        MenuController.instance.topTotalGemsText.Tick(-price);
                        cardElement.newTextContainer.SetActive(value: false);
                    }
                    AudioMap.PlayClipAt(AudioMap.instance[(item.currency == CurrencyType.Coins) ? "coinroll" : "gemCollect"], Vector3.zero, AudioMap.instance.uiMixerGroup);
                    PlayerDataManager.AddTankCards(tank, item.count, updateDailies: false);
                    TankPrefs.SaveAndSendToCloud(forced: true);
                    TankAnalytics.BoughtDailyOffer(tank, item.count, price, PlayerDataManager.GetTankUpgradeLevel(tank), currency);
                    if (currency == CurrencyType.Gems)
                    {
                        MenuController.ShowMenu <NewCardPopup>().Init(tank);
                    }
                });
            });
        }
    }