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.

50 lines
1.1 KiB

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. [SerializeField]
  9. protected List<InventoryData> AllElements = new List<InventoryData>();
  10. public void Add(LogicBlock element)
  11. {
  12. InventoryData data;
  13. try
  14. {
  15. data = AllElements.First(p => p.element == element);
  16. }
  17. catch
  18. {
  19. data = new InventoryData() { element = element };
  20. AllElements.Add(data);
  21. }
  22. data.Count++;
  23. }
  24. public void Remove(LogicBlock element) {
  25. if (!AllElements.Exists(p => p.element == element))
  26. return;
  27. InventoryData data = AllElements.First(p => p.element == element);
  28. if (!data.infinit)
  29. data.Count--;
  30. }
  31. [System.Serializable]
  32. public class InventoryData
  33. {
  34. public LogicBlock element;
  35. public int Count;
  36. public bool infinit = false;
  37. }
  38. }