[REQUEST] Add option to transfer items with the interactable script

karum

New member
Right now, I only have the option to disable the pickup.
But in the case of using it to make a chest, I want to transfer the content out of the inventory of the box, so the box remains empty.
Alternatively, give me the option to delete the content of the inventory. via calling a function of the pickup script.
 
Ok I'll add both.


In the Inventory script I'll add a RemoveAllItems functions with not parameters so that it can be called from the inspector unity events.
So that meant replacing the optional parameters on the existing function and adding a new function with no parameters.

Code:
/// <summary>
/// Remove all the items in the inventory.
/// </summary>
/// <returns>Returns the number of items added, 0 if no item was removed.</returns>
public void RemoveAllItems()
{
    RemoveAllItems(false, true);
}
/// <summary>
/// Remove all the items in the inventory.
/// </summary>
/// <param name="removeItemsFromIgnoredCollections">Should items be removed from ignored collections such as loadouts or Hide.</param>
/// <param name="disableEventsWhileRemoving">Should .</param>
/// <returns>Returns the number of items added, 0 if no item was removed.</returns>
public virtual void RemoveAllItems(bool removeItemsFromIgnoredCollections, bool disableEventsWhileRemoving)
{
    var previous = m_UpdateEventDisabled;
    if (disableEventsWhileRemoving) {
        m_UpdateEventDisabled = true;
    }
    
    for (int i = 0; i < m_ItemCollections.Count; i++) {
        var itemCollection = m_ItemCollections[i];
        if (removeItemsFromIgnoredCollections == false && IgnoreCollection(itemCollection)) { continue; }
        itemCollection.RemoveAll(disableEventsWhileRemoving);
    }
    if (disableEventsWhileRemoving) {
        m_UpdateEventDisabled = previous;
        UpdateInventory();
    }
}


Then for the ItemPickups, I'll add some options.
Please find attached the new InventoryPickup script

In my tests everything worked as expected. you can now choose to pickup dupplicates or the original items. And you can choose to remove the items from the pickup inventory if you want.

Let me know if that solves your issues
 

Attachments

  • InventoryPickup.cs
    5.4 KB · Views: 2
I added the removeallitems function, which I can now call from the pickup-script! Working, thank you!
 
Top