/// <summary> /// Select the given item /// </summary> /// <param name="itemToSelect"></param> public void Select(ShopItemPrefab itemToSelect) { // Deselect all for (int i = 0; i < transform.childCount; i++) { transform.GetChild(i).GetComponent <ShopItemPrefab>().Deselect(); } // Select one itemToSelect.border.color = itemToSelect.selectedBorder; itemToSelect.itemStatus = ItemStatus.Selected; // Atualize ShopManager ShopManager.instance.SelectItem(itemToSelect.id); }
private void InstantiateItens() { for (int i = 0; i < shopItens.Length; i++) { if (shopItens[i] != null) { ShopItemPrefab instantiatedItem = Instantiate(itemModel, transform); #if UNITY_EDITOR #region LogExceptions // itemModel null exceptions MyUtils.TreatNullExceptions(instantiatedItem.itemIconImage, "itemIconImage", "ItemModel"); MyUtils.TreatNullExceptions(instantiatedItem.itemNameLabel, "itemNameLabel", "ItemModel"); MyUtils.TreatNullExceptions(instantiatedItem.itemPriceLabel, "itemPriceLabel", "ItemModel"); MyUtils.TreatNullExceptions(instantiatedItem.currencyIcon, "currencyIcon", "ItemModel"); // shopIten[i] null exceptions MyUtils.TreatNullExceptions(shopItens[i].itemIcon, "itemIcon", shopItens[i].name); MyUtils.TreatNullExceptions(shopItens[i].itemName, "itemName", shopItens[i].name); MyUtils.TreatNullExceptions(shopItens[i].currencyIcon, "currencyIcon", shopItens[i].name); #endregion #endif instantiatedItem.id = shopItens[i].id; instantiatedItem.itemStatus = shopItens[i].itemStatus; // Opcional if (instantiatedItem.itemInfoLabel != null) // InfoLabel is opcional { instantiatedItem.itemInfoLabel.text = shopItens[i].description; } // Anyway instantiatedItem.itemIconImage.sprite = shopItens[i].itemIcon; instantiatedItem.itemIconImage.preserveAspect = shopItens[i].preserveIconAspect; instantiatedItem.itemNameLabel.text = shopItens[i].itemName; if (shopItens[i].itemStatus == ItemStatus.OnSale) { instantiatedItem.border.color = instantiatedItem.onSaleBorder; instantiatedItem.itemPriceLabel.text = shopItens[i].price.ToString(); instantiatedItem.currencyIcon.sprite = shopItens[i].currencyIcon; instantiatedItem.currencyIcon.preserveAspect = shopItens[i].preserveCurrencyAspect; instantiatedItem.buyButton.gameObject.SetActive(true); instantiatedItem.selectButton.gameObject.SetActive(false); instantiatedItem.buyPanelItemIcon.sprite = shopItens[i].itemIcon; instantiatedItem.buyPanelItemIcon.preserveAspect = shopItens[i].preserveIconAspect; instantiatedItem.buyPanelPrice.text = shopItens[i].price.ToString(); instantiatedItem.buyPanelCurrencyIcon.sprite = shopItens[i].currencyIcon; instantiatedItem.buyPanelCurrencyIcon.preserveAspect = shopItens[i].preserveCurrencyAspect; } else { RectTransform iconRect = instantiatedItem.itemIconImage.rectTransform; RectTransform nameRect = instantiatedItem.itemNameLabel.rectTransform; RectTransform priceRect = instantiatedItem.itemPriceLabel.rectTransform.parent.GetComponent <RectTransform>(); CentralizeIcon(iconRect, nameRect, priceRect); // Grow Icon iconRect.sizeDelta *= instantiatedItem.iconGrowPercentage + 1; instantiatedItem.itemPriceLabel.gameObject.SetActive(false); instantiatedItem.currencyIcon.gameObject.SetActive(false); instantiatedItem.buyButton.gameObject.SetActive(false); instantiatedItem.buyPanelItemIcon.gameObject.SetActive(false); instantiatedItem.buyPanelPrice.gameObject.SetActive(false); instantiatedItem.buyPanelCurrencyIcon.gameObject.SetActive(false); if (shopItens[i].itemStatus == ItemStatus.Selected) { instantiatedItem.border.color = instantiatedItem.selectedBorder; } else // itemStatus == ItemStatus.Bought { instantiatedItem.border.color = instantiatedItem.boughtBorder; instantiatedItem.selectButton.gameObject.SetActive(true); } } } } }