You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.1 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. using System.Linq;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. [CreateAssetMenu(menuName = "Major Project/Inventory", order = 150)]
  6. public class Inventory : ScriptableObject
  7. {
  8. public List<Data> BagItems { get { if (_bagItems == null) _bagItems = new List<Data>(); return _bagItems; } }
  9. [SerializeField]
  10. protected List<Data> _bagItems = new List<Data>();
  11. public void Add(LogicBlock element)
  12. {
  13. Data data;
  14. try
  15. {
  16. data = _bagItems.First(p => p.element == element);
  17. }
  18. catch
  19. {
  20. data = new Data() { element = element };
  21. _bagItems.Add(data);
  22. }
  23. data.Count++;
  24. }
  25. public void Remove(LogicBlock element) {
  26. if (!_bagItems.Exists(p => p.element == element))
  27. return;
  28. Data data = _bagItems.First(p => p.element == element);
  29. if (!data.infinit)
  30. data.Count--;
  31. }
  32. [System.Serializable]
  33. public class Data
  34. {
  35. public LogicBlock element;
  36. public int Count;
  37. public bool infinit = false;
  38. }
  39. }