Inventory

 avatar
user_3183455
csharp
17 days ago
1.1 kB
1
Indexable
Never
using UnityEngine;
 
namespace CuongMono.Item.Inventory
{
    [CreateAssetMenu(fileName = "Inventory", menuName = "CuongMono/Item/New Inventory")]
    public class Inventory : ScriptableObject
    {
        [Header("Inventory")]
        [SerializeField] public InventoryItemContainer itemContainer = new(10);
        [SerializeField] protected VoidEvent updateInventory = null;
        [SerializeField] private InventoryItemSlot item;
 
        private void OnEnable()
        {
            if (this.updateInventory == null) return;
            this.itemContainer.UpdateInventory += this.updateInventory.Raise;
        }
        private void OnDisable()
        {
            if (this.updateInventory == null) return;
            this.itemContainer.UpdateInventory -= this.updateInventory.Raise;
        }
     
        [ContextMenu(nameof(AddItem))]
        void AddItem()
        {
            this.itemContainer.AddItem(item);
        }
 
        [ContextMenu(nameof(ResetAllSlot))]
        void ResetAllSlot()
        {
            this.itemContainer.ResetItemSlots();
        }
 
 
    }
}
Leave a Comment