using System.Linq;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
[CreateAssetMenu(menuName = "Major Project/Inventory", order = 150)]
|
|
public class Inventory : ScriptableObject
|
|
{
|
|
|
|
public List<Data> BagItems { get { if (_bagItems == null) _bagItems = new List<Data>(); return _bagItems; } }
|
|
|
|
[SerializeField]
|
|
protected List<Data> _bagItems = new List<Data>();
|
|
|
|
public void Add(LogicBlock element)
|
|
{
|
|
|
|
Data data;
|
|
|
|
try
|
|
{
|
|
data = _bagItems.First(p => p.element == element);
|
|
}
|
|
catch
|
|
{
|
|
data = new Data() { element = element };
|
|
_bagItems.Add(data);
|
|
}
|
|
|
|
data.Count++;
|
|
}
|
|
|
|
public void Remove(LogicBlock element) {
|
|
|
|
if (!_bagItems.Exists(p => p.element == element))
|
|
return;
|
|
|
|
Data data = _bagItems.First(p => p.element == element);
|
|
|
|
if (!data.infinit)
|
|
data.Count--;
|
|
}
|
|
|
|
|
|
|
|
[System.Serializable]
|
|
public class Data
|
|
{
|
|
public LogicBlock element;
|
|
public int Count;
|
|
public bool infinit = false;
|
|
}
|
|
}
|