ce358dafcb
Fix inventory slots bug
77 lines
1.7 KiB
C#
77 lines
1.7 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
[System.Serializable]
|
|
public class InventoryManager : BaseWarehouseController
|
|
{
|
|
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;
|
|
}
|
|
}
|
|
|
|
private void Awake()
|
|
{
|
|
if(Instance == null)
|
|
{
|
|
Instance = this;
|
|
}else if (Instance != this)
|
|
{
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
|
|
public int AddToInventory(EquippableItem pickable)
|
|
{
|
|
if(this._items.Count <= MAX_ITEMS)
|
|
{
|
|
for(int slotNumber=0; slotNumber<MAX_ITEMS; slotNumber++)
|
|
{
|
|
if(!this._items.ContainsKey(slotNumber))
|
|
{
|
|
this._items[slotNumber] = pickable;
|
|
return slotNumber;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
|
|
///<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);
|
|
}
|
|
}
|
|
|
|
|
|
// public void DropItem()
|
|
// {
|
|
|
|
// }
|
|
}
|