Ejemplo n.º 1
0
        public void InitTab(ShopCategory cat)
        {
            _category = cat;

            int rowsRequired = 1 + (_category.ItemsInCategory.Count / ShopController.Instance.ItemsPerRow);

            _tabRows = new Transform[rowsRequired];

            for (int i = 0; i < rowsRequired; i++)
            {
                _tabRows[i] = Instantiate(_shopRowPrefab, _content);
            }

            int currentRowIndex = 0;

            for (int index = 0; index < _category.ItemsInCategory.Count; index++)
            {
                BaseBuyable  baseBuyable  = _category.ItemsInCategory[index];
                ShopItemView shopItemView = Instantiate(_shopItemPrefab, _tabRows[currentRowIndex]);
                shopItemView.Populate(baseBuyable);

                if ((index > 0) && ((index + 1) % ShopController.Instance.ItemsPerRow == 0))
                {
                    currentRowIndex++;
                }
            }
        }
        public void Populate(BaseBuyable buyable)
        {
            _buyable = buyable;

            if (buyable.Selected)
            {
                Select();
            }
            else if (buyable.Bought)
            {
                SetItemState(ShopItemState.Bought);
            }
            else
            {
                SetItemState(_buyable.Cost <= CoinPurse.Instance.TotalCoins ? ShopItemState.Affordable : ShopItemState.TooExpensive);
            }

            _itemImage.sprite     = buyable.ItemIcon;
            _currencyImage.sprite = ShopController.Instance.Setup.GetSpriteForCurrency(buyable.CurrencyType);
            _priceText.text       = buyable.Cost.ToString();
        }