2022-05-15 18:54:59 +02:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
[System.Serializable]
|
2022-06-05 01:57:57 +02:00
|
|
|
public class InventoryManager : BaseWarehouseController
|
2022-05-15 18:54:59 +02:00
|
|
|
{
|
|
|
|
public static int MAX_ITEMS = 5;
|
|
|
|
|
|
|
|
public static InventoryManager Instance;
|
2022-06-05 01:57:57 +02:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-19 14:38:22 +02:00
|
|
|
public int AddToInventory(EquippableItem pickable)
|
2022-05-15 18:54:59 +02:00
|
|
|
{
|
2022-06-05 01:57:57 +02:00
|
|
|
if(this._items.Count <= MAX_ITEMS)
|
2022-05-15 18:54:59 +02:00
|
|
|
{
|
2022-06-19 14:38:22 +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
|
|
|
}
|
2022-06-19 14:38:22 +02:00
|
|
|
|
|
|
|
return -1;
|
2022-05-15 18:54:59 +02:00
|
|
|
}
|
|
|
|
|
2022-06-19 14:38:22 +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;
|
|
|
|
}
|
2022-06-05 01:57:57 +02:00
|
|
|
|
|
|
|
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-06-05 01:57:57 +02:00
|
|
|
// }
|
2022-05-15 18:54:59 +02:00
|
|
|
}
|