using System.Collections.Generic;
using UnityEngine;
namespace Item
{
///
/// Inventory:
/// Inventory Name: The name of the inventory.
/// Inventory Size: The amount of size the inventory has.
///
/// Invetory Items: List of all items in the inventory. No items in the world are "destroyed"
/// instead all items in inventory are disabled, but can be looked up by their item name.
///
///
public class Inventory : MonoBehaviour
{
[SerializeField] private string inventoryName;
[SerializeField] private int inventorySize;
[SerializeField] private List inventoryItems;
private int inventoryReserved;
///
/// Adds item to inventory. Does not disable.
///
///
///
public bool AddItem(Item.CarryableItem item)
{
if (item.ItemSize + inventoryReserved > inventorySize) return false;
inventoryItems.Add(item.ItemName);
inventoryReserved += item.ItemSize;
//item.gameObject.SetActive(false);
return true;
}
private bool FindItemOfName(string name, out Item.CarryableItem item)
{
//NOTE: May not work. May need to move instead of disable objects.
var items = Resources.FindObjectsOfTypeAll();
foreach (var item2 in items)
if (item2.ItemName == name)
{
item = item2;
return true;
}
item = null;
return false;
}
public bool RemoveItem(string name)
{
Item.CarryableItem itemFound;
if (FindItemOfName(name, out itemFound))
{
itemFound.gameObject.SetActive(true);
inventoryItems.Remove(itemFound.ItemName);
inventoryReserved -= itemFound.ItemSize;
return true;
}
return false;
}
}
}