Scriptum/Assets/Scripts/Inventory/InventoryManager.cs

77 lines
1.7 KiB
C#
Raw Normal View History

2022-05-15 18:54:59 +02:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class InventoryManager : BaseWarehouseController
2022-05-15 18:54:59 +02:00
{
public static int MAX_ITEMS = 5;
public static InventoryManager Instance;
// temporary delegate dragged item to outside static object instance to remember it
[Space]
[SerializeField]
protected ISlot _draggedSlot;
public ISlot DraggedSlot
{
get { return _draggedSlot; }
set
{
_draggedSlot = value;
}
}
2022-05-15 18:54:59 +02:00
private void Awake()
{
if(Instance == null)
{
Instance = this;
}else if (Instance != this)
{
Destroy(gameObject);
}
}
public int AddToInventory(EquippableItem pickable)
2022-05-15 18:54:59 +02:00
{
if(this._items.Count <= MAX_ITEMS)
2022-05-15 18:54:59 +02:00
{
for(int slotNumber=0; slotNumber<MAX_ITEMS; slotNumber++)
{
if(!this._items.ContainsKey(slotNumber))
{
this._items[slotNumber] = pickable;
return slotNumber;
}
}
2022-05-15 18:54:59 +02:00
}
return -1;
2022-05-15 18:54:59 +02:00
}
///<summary>
/// Function for placed item in inventory on SPECYFIC position
/// Used by SceneInventoryManager for load saved items on their positions
///</summary>
public void SetupItemInInventory(int key, EquippableItem pickable)
{
this._items[key] = pickable;
}
protected override void SetupPanel()
{
if(this.dynamicPanel)
{
this.dynamicPanel.GetComponent<InventoryPanelController>().Setup(gameObject, _items);
}
}
2022-05-15 18:54:59 +02:00
// public void DropItem()
// {
// }
2022-05-15 18:54:59 +02:00
}