public void AddItemToInventory(ItensBase item) // adiciona um item ao inventario, testa se é Stack ou não. { // caso remover = true, entao remove o item e nao adiciona. bool foundItem = false; SlotsVendedor slotVazio = proxSlotVazio(); if (item.isStacklabe) { foreach (SlotsVendedor slot in InventarioSlots) { if (slot.currentItem != null && slot.currentItem.nameItem == item.nameItem) { slot.currentItem.addItem(); foundItem = true; Destroy(item.gameObject); } } if (!foundItem && slotVazio != null) { slotVazio.currentItem = item; } } else if (slotVazio != null) { slotVazio.currentItem = item; } item.gameObject.SetActive(false); }
public void AdicionarItemAoInventario() { foreach (SlotInventarioBehaviour slot in slots.InventarioSlots) { if (slot.currentItem == null) { GameObject objeto = Instantiate(selectedSlot.currentItem.prefab, transform.position, transform.rotation, playerPosition); objeto.SetActive(true); if (objeto.activeSelf) // só adiciona o objeto ao inventario caso ele apareça na cena { objeto.GetComponent <ItensBase>().AdicionaDiretamenteAoInventario(); //objeto.SetActive(true); selectedSlot.isSelected = false; selectedSlot = null; AtualizaSlotsAposCompra(); } /*slots.proxVazio().currentItem = selectedSlot.currentItem; * * selectedSlot.currentItem = null; * selectedSlot.isSelected = false; * selectedSlot = null;*/ // AddItemToInventory(selectedSlot.currentItem); //slot.currentItem = selectedSlot.currentItem; //selectedSlot.currentItem.removeAmount(99); //slot.currentItem.removeAmount(1); // slot.currentItem.RemoveItem(); break; } } }
private SlotsVendedor proxSlotVazio() //aponta o proximo slot vazio { SlotsVendedor slotToReturn = null; foreach (SlotsVendedor slot in InventarioSlots) { if (slot.currentItem == null) { slotToReturn = slot; break; } } return(slotToReturn); }
private void OnEnable() //Quando um objeto do inventario for selecionado, entao os botoes devem aparecer. { selectedSlot = null; buttonComprar.SetActive(true); }