Add Inventory system with Inventory, InventorySlot, and StatModifierItem classes; update character attributes to include level and experience

This commit is contained in:
2025-07-11 23:57:57 +02:00
parent c50b91eacb
commit 8f3a913b7e
19 changed files with 344 additions and 388 deletions

View 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;
}
}
}
}