first push 2
This commit is contained in:
73
Assets/Scripts/Inventory/Inventory.cs
Normal file
73
Assets/Scripts/Inventory/Inventory.cs
Normal file
@ -0,0 +1,73 @@
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
}
|
11
Assets/Scripts/Inventory/Inventory.cs.meta
Normal file
11
Assets/Scripts/Inventory/Inventory.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e2003234a0aa11e4797fe8fe9376402f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user