/// <summary> /// Populates the store list of inventory items /// </summary> /// <param name="inventoryList"></param> public void PopulateInventory(MerchantInventoryDetails inventoryList) { ClearInventory(); MerchantInventory = inventoryList; foreach (var item in inventoryList.InventoryItems) { GameObject newItem = Instantiate(ItemTemplate, _scrollViewContent); newItem.transform.localScale = Vector3.one; newItem.transform.FindChild("Image/ItemImage").GetComponent <Image>().sprite = item.Sprite; newItem.transform.FindChild("Name").GetComponent <Text>().text = item.Name; newItem.transform.FindChild("Description").GetComponent <Text>().text = item.Description; foreach (var cur in item.PurchasePrice) { GameObject newCurrency = Instantiate(CurrencyTemplate, newItem.transform.FindChild("Currency/List")); newCurrency.transform.localScale = Vector3.one; newCurrency.transform.FindChild("Image").GetComponent <Image>().sprite = cur.Currency.Image; newCurrency.transform.FindChild("Amount").GetComponent <Text>().text = cur.Amount.ToString(); } newItem.transform.FindChild("Currency/BuyBtn").GetComponent <Button>().onClick.AddListener(BuyOnClick); } }
/// <summary> /// Populates the store list of inventory items /// </summary> /// <param name="inventoryList"></param> public void PopulateInventory(MerchantInventoryDetails inventoryList) { ClearInventory(); MerchantInventory = inventoryList; foreach (var item in inventoryList.InventoryItems) { CreateInventoryItem(item); } }
/// <summary> /// Clears out any existing inventory UI items /// </summary> public void ClearInventory() { MerchantInventory = null; //Since this starts out as disabled, we need to do a check the first time we try to access the content element, as we may not have a reference to it. if (_scrollViewContent == null) { _scrollViewContent = transform.FindChild("Scroll View/Viewport/Content"); } foreach (Transform child in _scrollViewContent) { Destroy(child.gameObject); } }