66 lines
1.7 KiB
C#
66 lines
1.7 KiB
C#
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
|
||
|
// 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;
|
||
|
}
|
||
|
|
||
|
protected abstract void SetupPanel();
|
||
|
|
||
|
// public virtual void CloseOnClick()
|
||
|
// {
|
||
|
// Destroy(gameObject); // destroy panel
|
||
|
|
||
|
// if(_panel)
|
||
|
// {
|
||
|
// _inventory.GetComponent<InventoryManager>().ClosePanel();
|
||
|
// }
|
||
|
// }
|
||
|
|
||
|
public void SetItemOnPosition(int _keyPosition, Item _item)
|
||
|
{
|
||
|
this._items[_keyPosition] = _item;
|
||
|
}
|
||
|
|
||
|
public void RemoveItemFromPosition(int _keyPosition)
|
||
|
{
|
||
|
this._items.Remove(_keyPosition);
|
||
|
}
|
||
|
}
|
||
|
|