private void RefreshInventoryItems() { foreach (Transform child in itemSlotContainer) { if (child == itemSlotTemplate) { continue; } Destroy(child.gameObject); } int x = 0; int y = 0; float itemSlotCellSize = 128f; foreach (Item item in inventory.getItemList()) { RectTransform itemSlotRectTransform = Instantiate(itemSlotTemplate, itemSlotContainer).GetComponent <RectTransform>(); itemSlotRectTransform.gameObject.SetActive(true); itemSlotRectTransform.GetComponent <Button_UI>().ClickFunc = () => { inventory.UseItem(item); }; itemSlotRectTransform.GetComponent <Button_UI>().MouseRightClickFunc = () => { Item duplicateItem = new Item { itemType = item.itemType, amount = item.amount }; inventory.RemoveItem(item); ItemWorld.DropItem(player.GetPosition(), duplicateItem); }; itemSlotRectTransform.anchoredPosition = new Vector2(x * itemSlotCellSize, y * itemSlotCellSize); Image image = itemSlotRectTransform.Find("Item_Icon").GetComponent <Image>(); image.sprite = item.getSprite(); TextMeshProUGUI uiText = itemSlotRectTransform.Find("ItemAmount-text").GetComponent <TextMeshProUGUI>(); if (item.amount > 1) { uiText.SetText(item.amount.ToString()); } else { uiText.SetText(""); } x++; if (x > 5) { x = 0; y++; } } }
public void refreshInventoryItems() { foreach (Transform child in itemSlotContainer) { if (child == itemSlotTemplate) { continue; } Destroy(child.gameObject); } float x = -280f; float y = 190f; float itemSlotCellSize = 140f; foreach (Item item in inventory.getItemList()) { if (y < -230f) { Debug.Log("Limite do inventário atingido"); return; } RectTransform itemSlotRectTransform = Instantiate(itemSlotTemplate, itemSlotContainer).GetComponent <RectTransform>(); itemSlotRectTransform.gameObject.SetActive(true); itemSlotRectTransform.anchoredPosition = new Vector2(x, y); Image image = itemSlotRectTransform.Find("image").GetComponent <Image>(); image.sprite = Resources.Load <Sprite>(item.sprite); Text amountText = itemSlotRectTransform.Find("amountText").GetComponent <Text>(); if (item.amount == 0) { amountText.text = ""; } else { amountText.text = item.amount.ToString(); } x += itemSlotCellSize; if (x > 280) { x = -280; y -= itemSlotCellSize; } } }
void setListofStorage() { Inventory inv = inventory.GetComponent <Inventory>(); storageItems = inv.getItemList(); }