示例#1
0
    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.");
        }
    }
示例#2
0
    public void PlayPlasticPickupSfx(Interactable interactableObject)
    {
        PlasticInteractable plasticObject = interactableObject as PlasticInteractable;

        audioSource.clip = plasticObject.PlasticData.PickupSfx;
        if (audioSource.clip != null)
        {
            audioSource.Play();
        }
    }
示例#3
0
 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);
 }
示例#4
0
 private bool IsStackable(PlasticInteractable item)
 {
     foreach (Slot slot in InventorySlots)
     {
         if (slot.StackItem(item))
         {
             return(true);
         }
     }
     return(false);
 }
示例#5
0
    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);
    }
示例#6
0
    public override void Act()
    {
        if (target == null)
        {
            return;
        }

        PlasticInteractable plastic = target.GetComponent <PlasticInteractable>();

        if (plastic != null)
        {
            AddToInventory(plastic);
        }
    }
示例#7
0
    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);
    }
示例#8
0
    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);
            }
        }
    }
示例#9
0
    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);
    }
示例#10
0
    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;
    }
示例#11
0
 public void AddItem(PlasticInteractable item)
 {
     AddToInventory(item);
 }