public void AddToEmptySlot(PlasticInteractable interactableObj, bool alreadyInPlayerData = false) { if (inventorySlots[currentEmptySlot].inventoryItem == null) { // Update session data if (!alreadyInPlayerData) { sessionData.Inventory.Add(interactableObj.PlasticData); sessionData.TotalPickedUp++; } // Store to inventory slot inventorySlots[currentEmptySlot].inventoryItem = interactableObj; // Update the slot image inventorySlots[currentEmptySlot].UpdateImage(); // Deactivate interactableObject in scene interactableObj.gameObject.SetActive(false); // Move to next empty slot currentEmptySlot++; currentEmptySlot %= slotCount; // Avoid index going out of range // Broadcast that trash has been added to the inventory OnAddedToInventory.Invoke(interactableObj); } else { OnInventoryFull.Invoke(); Debug.Log("Inventory is full."); } }
public void PlayPlasticPickupSfx(Interactable interactableObject) { PlasticInteractable plasticObject = interactableObject as PlasticInteractable; audioSource.clip = plasticObject.PlasticData.PickupSfx; if (audioSource.clip != null) { audioSource.Play(); } }
public bool AddItem(PlasticInteractable item) { items.Add(item); // Add item SlotItemIcon.sprite = item.PlasticData.Sprite; // Set slot item icon to new item icon SlotItemIcon.color = Color.white; // Reset transparency to default // item.ItemSlot = this; // Item reference to this slot StackSize.color = Color.black; // Set stack size color transparent UpdateStackUI(); // Update stack size text return(true); }
private bool IsStackable(PlasticInteractable item) { foreach (Slot slot in InventorySlots) { if (slot.StackItem(item)) { return(true); } } return(false); }
public bool StackItem(PlasticInteractable item) { // Check if the item has the same name and if its count is less than stack size if (item.name == item.name && items.Count < item.PlasticData.StackSize && !IsEmpty) { items.Add(item); // item.ItemSlot = this; UpdateStackUI(); return(true); } return(false); }
public override void Act() { if (target == null) { return; } PlasticInteractable plastic = target.GetComponent <PlasticInteractable>(); if (plastic != null) { AddToInventory(plastic); } }
public void AddToInventory(PlasticInteractable item) { //Checks if item can be placed in stack if (item.PlasticData.StackSize > 0) { if (IsStackable(item)) { return; } } // Else place in a new empty slot IsNotStackable(item); }
public void RemoveItem(PlasticInteractable item) { //Checks if item count is 0 if (!IsEmpty) { //Debug.Log("Deleted"); items.RemoveAt(items.Count - 1); UpdateStackUI(); // Updates inventory UI //If its empty destroy if (IsEmpty) { Destroy(item.gameObject); } } }
private bool IsNotStackable(PlasticInteractable item) { foreach (Slot slot in InventorySlots) { //Checks if slot is empty if (slot.IsEmpty) { slot.AddItem(Instantiate(item)); // Add item to slot OnAddedToInventory.Invoke(item); return(true); } } // Inventory is full cannot add anymore items OnInventoryFull.Invoke(); Debug.Log("Inventory is full."); return(false); }
protected void AddToInventory(PlasticInteractable interactableObj, bool alreadyInPlayerData = false) { //if (playerDataHandler.playerData.Inventory.Count == Inventory.GetSlotCount()) //{ // Inventory.OnInventoryFull.Invoke(); // return; //} //if (interactableObj != null) // Inventory.AddToEmptySlot(interactableObj); //if (!alreadyInPlayerData) //{ // // Add the plastic scriptable object to player data list // playerDataHandler.playerData.Inventory.Add(interactableObj.GetPlastic()); // // Increase total plastic collected in player data // playerDataHandler.playerData.TotalTrash++; //} /* Old Working Method * if (sessionData.Inventory.Count == Inventory.GetSlotCount()) * { * Inventory.OnInventoryFull.Invoke(); * return; * } * * if (interactableObj != null) * Inventory.AddToEmptySlot(interactableObj, alreadyInPlayerData); * * * // Remove the reference to the previous obejct * target = null; */ Inventory.AddItem(interactableObj); interactableObj.GetComponent <SpriteRenderer>().enabled = false; // Hides this sprite Destroy(interactableObj); target = null; }
public void AddItem(PlasticInteractable item) { AddToInventory(item); }