using System.Collections; using System.Collections.Generic; using UnityEngine; public class ChestController : BaseWarehouseController { [SerializeField] public GameObject chest; [SerializeField] public List developerList = new List(); // FOR DEVELOPER TESTE - remove later !!! bool isTrigerred = false; // Start is called before the first frame update void Start() { chest = gameObject; // set object on current GameObject // FOR DEVELOPER TESTE - remove later !!! for(int i = 0; i < developerList.Count; i++) { SetItemOnPosition(i, developerList[i]); } } // Update is called once per frame void Update() { if (this._panel && this.isTrigerred && !this.isOpen) // we can open chest only when its closed { if (Input.GetKeyDown(KeyCode.E)) { this.OpenPanel(); InventoryManager.Instance.OpenPanel(); EquipmentManager.Instance.OpenPanel(); } } if (!InventoryManager.Instance.isOpen) { if (Input.GetKeyDown(KeyCode.I)) { InventoryManager.Instance.OpenPanel(); } } } void OnTriggerExit2D(Collider2D collision) { if (this._panel != null) { this.ClosePanel(); } this.isTrigerred = false; } private void OnTriggerEnter2D(Collider2D collision) { if (collision.tag == "Player") { this.isTrigerred = true; } } public override void ClosePanel() { base.ClosePanel(); InventoryManager.Instance.ClosePanel(); EquipmentManager.Instance.ClosePanel(); } protected override void SetupPanel() { if(this.dynamicPanel) { this.dynamicPanel.GetComponent().Setup(gameObject, _items); } } // WARNING // DANGER - functon override position which may be not free /// /// Function for placed item in inventory on SPECYFIC position /// Used by SceneInventoryManager for load saved items on their positions /// // WHAT WITH FUNCTION - setupItemOnPosition() - ??? public void SetupItemInChest(int key, EquippableItem pickable) { this._items[key] = pickable; } public override void SetItemOnPosition(int _keyPosition, Item _item) { // Drag setup first end second object on the same panel - should only one - this wwere dropped item // Becouse of this source slot from other panel is settuping in dropped panel too - list get empty item and it cause errors if(_item != null) { this._items[_keyPosition] = _item; Debug.Log("Put item on chest"+_item.name); // Inform Map Chests manager about update - update list to be compliant with the local list SceneChestManager.Instance.AddItemToChest(gameObject.name, _keyPosition, (EquippableItem)_item); } // if we assign null its removed later in EndDrag method } public override void RemoveItemFromPosition(int _keyPosition) { base.RemoveItemFromPosition(_keyPosition); Debug.Log("Pick up item from chest"); // Inform Map Chests manager about update - update list to be compliant with the local list SceneChestManager.Instance.RemoveItemFromChest(gameObject.name, _keyPosition); } }