2024-01-02 21:39:53 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
// ReSharper disable once CheckNamespace
|
|
|
|
namespace BlueWaterProject
|
|
|
|
{
|
|
|
|
[Serializable]
|
|
|
|
public class PlayerInventory
|
|
|
|
{
|
2024-01-21 17:42:31 +00:00
|
|
|
[SerializeField] private List<Item> items = new();
|
2024-01-02 21:39:53 +00:00
|
|
|
|
2024-01-21 17:42:31 +00:00
|
|
|
public void AddItem(IItem item)
|
2024-01-02 21:39:53 +00:00
|
|
|
{
|
2024-01-21 17:42:31 +00:00
|
|
|
var existingItem = items.Find(i => i.ItemName == item.ItemName);
|
|
|
|
|
|
|
|
if (existingItem != null)
|
2024-01-02 21:39:53 +00:00
|
|
|
{
|
2024-01-21 17:42:31 +00:00
|
|
|
existingItem.ItemCount += item.ItemCount;
|
2024-01-02 21:39:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-01-21 17:42:31 +00:00
|
|
|
items.Add(new Item(item.ItemName, item.ItemCount));
|
2024-01-02 21:39:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|