/// ---------------------------------------------
/// Ultimate Character Controller
/// Copyright (c) Opsive. All Rights Reserved.
/// https://www.opsive.com
/// ---------------------------------------------
namespace Opsive.UltimateCharacterController.Objects.CharacterAssist
{
using Opsive.UltimateCharacterController.Inventory;
using UnityEngine;
///
/// Extends ItemPickupBase to allow for ItemIdentifier pickups.
///
public class ItemPickup : ItemPickupBase
{
[Tooltip("An array of ItemIdentifiers to be picked up.")]
[UnityEngine.Serialization.FormerlySerializedAs("m_ItemTypeCounts")]
[SerializeField] protected ItemDefinitionAmount[] m_ItemDefinitionAmounts;
///
/// Returns the ItemDefinitionAmount that the ItemPickup contains.
///
/// The ItemDefinitionAmount that the ItemPickup contains.
public override ItemDefinitionAmount[] GetItemDefinitionAmounts()
{
return m_ItemDefinitionAmounts;
}
///
/// Sets the ItemPickup ItemDefinitionAmounts value.
///
/// The ItemDefinitionAmount that should be set.
public override void SetItemDefinitionAmounts(ItemDefinitionAmount[] itemDefinitionAmounts)
{
m_ItemDefinitionAmounts = itemDefinitionAmounts;
}
///
/// Internal method which picks up the ItemIdentifier.
///
/// The character that should pick up the ItemIdentifier.
/// The inventory belonging to the character.
/// The slot ID that picked up the item. A -1 value will indicate no specified slot.
/// Should the item be picked up immediately?
/// Should the item be force equipped?
/// True if an ItemIdentifier was picked up.
protected override bool DoItemIdentifierPickupInternal(GameObject character, InventoryBase inventory, int slotID, bool immediatePickup, bool forceEquip)
{
// Add the ItemIdentifiers to the Inventory. This allows the character to pick up the actual item and any consumable ItemIdentifier (such as ammo).
var pickedUp = false;
if (m_ItemDefinitionAmounts != null) {
for (int i = 0; i < m_ItemDefinitionAmounts.Length; ++i) {
if (inventory.Pickup(m_ItemDefinitionAmounts[i].ItemIdentifier, m_ItemDefinitionAmounts[i].Amount, slotID, immediatePickup, forceEquip)) {
pickedUp = true;
}
}
}
return pickedUp;
}
}
}