2022-06-05 01:57:57 +02:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
2022-06-20 18:23:22 +02:00
|
|
|
using System.Linq;
|
2022-06-05 01:57:57 +02:00
|
|
|
|
|
|
|
// T will be type panel: inventory, equipment, chest
|
|
|
|
abstract public class BaseWarehouseController : MonoBehaviour
|
|
|
|
{
|
|
|
|
[SerializeField] public GameObject _panel;
|
|
|
|
[SerializeField] public Dictionary<int, Item> _items = new Dictionary<int, Item>();
|
|
|
|
|
|
|
|
|
|
|
|
protected GameObject dynamicPanel;
|
|
|
|
|
|
|
|
public bool isOpen = false;
|
|
|
|
|
|
|
|
|
|
|
|
// Create panel instance on scene on special position and passed content (item list)
|
|
|
|
public void OpenPanel()
|
|
|
|
{
|
|
|
|
GameObject globalGUI = GameObject.FindGameObjectsWithTag("GUI")[0];
|
|
|
|
|
|
|
|
if(globalGUI)
|
|
|
|
{
|
|
|
|
this.dynamicPanel = Instantiate(_panel, _panel.transform.position, Quaternion.identity, globalGUI.transform); // 4'th arg allow set object as child
|
|
|
|
|
|
|
|
this.dynamicPanel.transform.localPosition = _panel.transform.position; // prevent overwritten position by... environment???
|
|
|
|
|
|
|
|
this.SetupPanel(); // bind pandel to current chest
|
|
|
|
|
|
|
|
isOpen = true;
|
|
|
|
} else {
|
|
|
|
Debug.Log("Can't find global GUI object!!!");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual void ClosePanel()
|
|
|
|
{
|
|
|
|
Destroy(dynamicPanel);
|
|
|
|
isOpen = false;
|
|
|
|
}
|
|
|
|
|
2022-06-20 18:23:22 +02:00
|
|
|
public KeyValuePair<int, Item> FindItemInWarehouse(string itemName)
|
|
|
|
{
|
|
|
|
return this._items.Where(item => item.Value.name == itemName).FirstOrDefault();
|
|
|
|
}
|
|
|
|
|
2022-06-05 01:57:57 +02:00
|
|
|
protected abstract void SetupPanel();
|
|
|
|
|
2022-06-05 16:51:08 +02:00
|
|
|
public virtual void SetItemOnPosition(int _keyPosition, Item _item)
|
2022-06-05 01:57:57 +02:00
|
|
|
{
|
|
|
|
this._items[_keyPosition] = _item;
|
|
|
|
}
|
|
|
|
|
2022-06-05 16:51:08 +02:00
|
|
|
public virtual void RemoveItemFromPosition(int _keyPosition)
|
2022-06-05 01:57:57 +02:00
|
|
|
{
|
|
|
|
this._items.Remove(_keyPosition);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|