예제 #1
0
    private void TryBuyItem(ShopItem.ShopItemType itemType)
    {
        ShopItem.ItemCost itemCost = ShopItem.GetCost(itemType);

        if (_coins.Value >= itemCost.coins && _stars.Value >= itemCost.stars)
        {
            BoughtItem(itemType);
            _coins.Value -= itemCost.coins;
            _stars.Value -= itemCost.stars;
            _changeDataGameEvent.Raise();
            AudioManager.Instance.PlaySound2D(SoundLibrary.Sound.ClickButton02);
        }
    }
예제 #2
0
    private void CreateItemButton(ShopItem.ShopItemType itemType, Sprite itemSprite, string itemName, string itemDescription, ShopItem.ItemCost itemCost)
    {
        Transform shopItemTransform = Instantiate(_shopItemTemplate, _container);

        shopItemTransform.SetParent(_container);
        shopItemTransform.Find("ItemName").GetComponent <TextMeshProUGUI>().text        = itemName;
        shopItemTransform.Find("ItemDescription").GetComponent <TextMeshProUGUI>().text = itemDescription;

        shopItemTransform.Find("ItemCoinValue").GetComponent <TextMeshProUGUI>().text = itemCost.coins.ToString();
        shopItemTransform.Find("ItemStarValue").GetComponent <TextMeshProUGUI>().text = itemCost.stars.ToString();

        if (itemCost.stars == 0)
        {
            shopItemTransform.Find("ItemStarValue").gameObject.SetActive(false);
            shopItemTransform.Find("StarIcon").gameObject.SetActive(false);
        }


        if (itemCost.coins > _coins.Value || itemCost.stars > _stars.Value)
        {
            shopItemTransform.Find("ItemCoinValue").GetComponent <TextMeshProUGUI>().fontMaterial = _textMaterialRed;
            shopItemTransform.Find("ItemStarValue").GetComponent <TextMeshProUGUI>().fontMaterial = _textMaterialRed;
            shopItemTransform.Find("BuyButton").GetComponent <Button>().interactable = false;
        }

        shopItemTransform.Find("IconImage").GetComponent <Image>().sprite = itemSprite;
        shopItemTransform.Find("BuyButton").GetComponent <Button>().onClick.AddListener(() =>
        {
            // Clicked on shop item button
            TryBuyItem(itemType);
        });
    }