2023-03-14 00:59:59 +01:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Inventory:
|
|
|
|
/// <list type="bullet">Inventory Name: The name of the inventory.</list>
|
|
|
|
/// <list type="bullet">Inventory Size: The amount of size the inventory has.</list>
|
|
|
|
/// <list type="bullet">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.</list>
|
|
|
|
/// </summary>
|
|
|
|
public class Inventory : MonoBehaviour
|
|
|
|
{
|
|
|
|
[SerializeField]
|
|
|
|
private string inventoryName;
|
|
|
|
[SerializeField]
|
|
|
|
private int inventorySize;
|
|
|
|
[SerializeField]
|
|
|
|
private List<string> inventoryItems;
|
|
|
|
private int inventoryReserved;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Adds item to inventory. Does not disable.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="item"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
public bool AddItem(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 CarryableItem item)
|
|
|
|
{
|
|
|
|
//NOTE: May not work. May need to move instead of disable objects.
|
|
|
|
CarryableItem[] items = Resources.FindObjectsOfTypeAll<CarryableItem>();
|
|
|
|
|
|
|
|
foreach (CarryableItem item2 in items)
|
|
|
|
{
|
|
|
|
if (item2.ItemName == name)
|
|
|
|
{
|
|
|
|
|
|
|
|
item = item2;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
item = null;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
public bool RemoveItem(string name)
|
|
|
|
{
|
|
|
|
|
|
|
|
CarryableItem itemFound;
|
|
|
|
if (FindItemOfName(name,out itemFound))
|
|
|
|
{
|
|
|
|
itemFound.gameObject.SetActive(true);
|
|
|
|
inventoryItems.Remove(itemFound.ItemName);
|
|
|
|
inventoryReserved -= itemFound.ItemSize;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
2023-04-18 04:29:21 +02:00
|
|
|
|
2023-03-14 00:59:59 +01:00
|
|
|
|
|
|
|
}
|