Add Inventory system with Inventory, InventorySlot, and StatModifierItem classes; update character attributes to include level and experience
This commit is contained in:
66
Assets/Scripts/Inventory/Inventory.cs
Normal file
66
Assets/Scripts/Inventory/Inventory.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using System.Collections.Generic;
|
||||
using Sirenix.Serialization;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Inventory
|
||||
{
|
||||
public class Inventory : MonoBehaviour
|
||||
{
|
||||
[OdinSerialize, SerializeField] private List<InventorySlot> weaponSlots = new();
|
||||
[OdinSerialize, SerializeField] private List<InventorySlot> itemSlots = new();
|
||||
|
||||
public IReadOnlyList<InventorySlot> WeaponSlots => weaponSlots.AsReadOnly();
|
||||
public IReadOnlyList<InventorySlot> ItemSlots => itemSlots.AsReadOnly();
|
||||
|
||||
public void AddWeapon(WeaponItem weaponItem)
|
||||
{
|
||||
foreach (var slot in weaponSlots)
|
||||
{
|
||||
if (slot.item == weaponItem) return;
|
||||
}
|
||||
|
||||
weaponSlots.Add(new InventorySlot { item = weaponItem, quantity = 1 });
|
||||
}
|
||||
|
||||
public void AddItem(ScriptableObject item)
|
||||
{
|
||||
foreach (var slot in itemSlots)
|
||||
{
|
||||
if (slot.item != item) continue;
|
||||
|
||||
slot.quantity++;
|
||||
return;
|
||||
}
|
||||
|
||||
itemSlots.Add(new InventorySlot { item = item, quantity = 1 });
|
||||
}
|
||||
|
||||
public void RemoveWeapon(WeaponItem weaponItem)
|
||||
{
|
||||
for (var i = 0; i < weaponSlots.Count; i++)
|
||||
{
|
||||
if (weaponSlots[i].item != weaponItem) continue;
|
||||
|
||||
if (--weaponSlots[i].quantity <= 0)
|
||||
{
|
||||
weaponSlots.RemoveAt(i);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveItem(ScriptableObject item)
|
||||
{
|
||||
for (var i = 0; i < itemSlots.Count; i++)
|
||||
{
|
||||
if (itemSlots[i].item != item) continue;
|
||||
|
||||
if (--itemSlots[i].quantity <= 0)
|
||||
{
|
||||
itemSlots.RemoveAt(i);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/Scripts/Inventory/Inventory.cs.meta
Normal file
3
Assets/Scripts/Inventory/Inventory.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9810b6967ffd4c3589464d687e982ee6
|
||||
timeCreated: 1752268911
|
13
Assets/Scripts/Inventory/InventorySlot.cs
Normal file
13
Assets/Scripts/Inventory/InventorySlot.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using Sirenix.Serialization;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Inventory
|
||||
{
|
||||
[Serializable]
|
||||
public class InventorySlot
|
||||
{
|
||||
[OdinSerialize] public ScriptableObject item;
|
||||
[OdinSerialize] public int quantity;
|
||||
}
|
||||
}
|
3
Assets/Scripts/Inventory/InventorySlot.cs.meta
Normal file
3
Assets/Scripts/Inventory/InventorySlot.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 88a6fde0304145ba9f9cdd1b2782e363
|
||||
timeCreated: 1752268731
|
19
Assets/Scripts/Inventory/StatModifierItem.cs
Normal file
19
Assets/Scripts/Inventory/StatModifierItem.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System.Collections.Generic;
|
||||
using Interfaces;
|
||||
using Sirenix.OdinInspector;
|
||||
using Sirenix.Serialization;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Inventory
|
||||
{
|
||||
[CreateAssetMenu(menuName = "Game/Item/StatModifierItem")]
|
||||
public class StatModifierItem : SerializedScriptableObject
|
||||
{
|
||||
public string itemName;
|
||||
[TextArea] public string description;
|
||||
public Sprite icon;
|
||||
|
||||
public List<IStatModifier> cures = new();
|
||||
public List<IStatModifier> curses = new();
|
||||
}
|
||||
}
|
3
Assets/Scripts/Inventory/StatModifierItem.cs.meta
Normal file
3
Assets/Scripts/Inventory/StatModifierItem.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c437a5565f39495281bf1dd14dd6ba40
|
||||
timeCreated: 1752268788
|
14
Assets/Scripts/Inventory/WeaponItem.cs
Normal file
14
Assets/Scripts/Inventory/WeaponItem.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Sirenix.Serialization;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Inventory
|
||||
{
|
||||
[CreateAssetMenu(menuName = "Game/Item/WeaponItem")]
|
||||
public class WeaponItem : ScriptableObject
|
||||
{
|
||||
[OdinSerialize] public string weaponName;
|
||||
[OdinSerialize, TextArea] public string description;
|
||||
[OdinSerialize] public GameObject prefab;
|
||||
[OdinSerialize] public Sprite icon;
|
||||
}
|
||||
}
|
3
Assets/Scripts/Inventory/WeaponItem.cs.meta
Normal file
3
Assets/Scripts/Inventory/WeaponItem.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: efa44a330e8343c08e3af638d466c118
|
||||
timeCreated: 1752268856
|
Reference in New Issue
Block a user