Assemblies Made and Refactored Code Folders
Created assemblies for the new design code. Relocated legacy scripts into a legacy folder and made a "new_design" folder for new design.
This commit is contained in:
70
Assets/Scripts/Legacy/Inventory/Inventory.cs
Normal file
70
Assets/Scripts/Legacy/Inventory/Inventory.cs
Normal file
@ -0,0 +1,70 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Item
|
||||
{
|
||||
/// <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(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<Item.CarryableItem>();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Legacy/Inventory/Inventory.cs.meta
Normal file
11
Assets/Scripts/Legacy/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:
|
57
Assets/Scripts/Legacy/Inventory/TempInventory.cs
Normal file
57
Assets/Scripts/Legacy/Inventory/TempInventory.cs
Normal file
@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Item
|
||||
{
|
||||
[Serializable]
|
||||
public class TempInventoryBuilderItem
|
||||
{
|
||||
public string name;
|
||||
public int quantity;
|
||||
}
|
||||
|
||||
public class TempInventory : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private List<TempInventoryBuilderItem> initialInvent = new();
|
||||
|
||||
private readonly Dictionary<string, int> inventory = new();
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
foreach (var item in initialInvent) inventory[item.name] = item.quantity;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
}
|
||||
|
||||
public int GetQuantityOf(string name)
|
||||
{
|
||||
if (inventory.ContainsKey(name)) return inventory[name];
|
||||
return 0;
|
||||
}
|
||||
|
||||
public bool Add(string name, int quantity = 1)
|
||||
{
|
||||
if (inventory.ContainsKey(name))
|
||||
inventory[name] += quantity;
|
||||
else
|
||||
inventory.Add(name, quantity);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Remove(string name, int quantity = 1)
|
||||
{
|
||||
if (inventory.ContainsKey(name))
|
||||
{
|
||||
inventory[name] = Mathf.Max(inventory[name] - quantity, 0);
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Legacy/Inventory/TempInventory.cs.meta
Normal file
11
Assets/Scripts/Legacy/Inventory/TempInventory.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0409b6b23ffc72640a6491311e0f6a26
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user