using System; using UnityEngine; /// /// A Slot can contain an item and its count. Used for the inventory. /// [Serializable] public class Slot { [Header("Slot")] [Tooltip("The item which is in this slot")] [SerializeField] Item item = null; [Tooltip("The count of the contained item")] [SerializeField] int count = 0; #region GETTER & SETTER public Item GetItem() => item; public void SetItem(Item _item) => item = _item; public int GetCount() => count; public void SetCount(int newCount) { count = newCount; if (count <= 0) Clear(); } #endregion /// /// AddCount adds a value to the current count. The slot does not have any logic for the maximum stack size. /// /// Value which should be added. public void AddCount(int value) => count += value; /// /// RemoveCount removes a value from the current count. It clears the slot if count == 0. /// /// Value which should be removed. public void RemoveCount(int value) { count -= value; if (count <= 0) Clear(); } /// /// Sets the count to 0 /// public void ResetCount() => count = 0; /// /// Clears the hole slot /// public void Clear() { item = null; count = 0; } /// /// Gives you a copy of this slot. /// /// Copy of this slot public Slot Copy() { Slot slot = new Slot(); slot.SetCount(count); slot.SetItem(item); return slot; } /// /// Sets the item and count of this slot. /// /// /// public void Set(Item _item, int _count = 1) { item = _item; count = _count; } }