133 lines
3.4 KiB
C#
133 lines
3.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using GUI_Scripts;
|
|
using UnityEngine;
|
|
|
|
public class ChestController : BaseWarehouseController
|
|
{
|
|
[SerializeField] public GameObject chest;
|
|
[SerializeField] public List<Item> developerList = new List<Item>(); // FOR DEVELOPER TESTE - remove later !!!
|
|
private Animator m_Animator;
|
|
bool isTrigerred = false;
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
m_Animator = gameObject.GetComponent<Animator>();
|
|
chest = gameObject; // set object on current GameObject
|
|
|
|
// FOR DEVELOPER TESTE - remove later !!!
|
|
for(int i = 0; i < developerList.Count; i++)
|
|
{
|
|
SetItemOnPosition(i, developerList[i]);
|
|
}
|
|
}
|
|
|
|
private bool beingHandled = false;
|
|
private static bool Opening;
|
|
private static bool Closing;
|
|
private IEnumerator OpenChestWithAnimation()
|
|
{
|
|
beingHandled = true;
|
|
// process pre-yield
|
|
m_Animator.SetTrigger("OpenIt");
|
|
yield return new WaitForSeconds( 0.4f );
|
|
this.OpenPanel();
|
|
InventoryManager.Instance.OpenPanel();
|
|
EquipmentManager.Instance.OpenPanel();
|
|
m_Animator.ResetTrigger("OpenIt");
|
|
// process post-yield
|
|
beingHandled = false;
|
|
}
|
|
|
|
// 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) && !beingHandled)
|
|
{
|
|
StartCoroutine(OpenChestWithAnimation());
|
|
}
|
|
}
|
|
|
|
if (!InventoryManager.Instance.isOpen)
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.I))
|
|
{
|
|
InventoryManager.Instance.OpenPanel();
|
|
EquipmentManager.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();
|
|
if (!beingHandled)
|
|
{
|
|
StartCoroutine(CloseChestWithAnimation());
|
|
}
|
|
ReactivateAnimation();
|
|
}
|
|
|
|
public void CloseChestWithAnimationForOtherPanels()
|
|
{
|
|
if (!beingHandled)
|
|
{
|
|
StartCoroutine(CloseChestWithAnimation());
|
|
}
|
|
ReactivateAnimation();
|
|
}
|
|
|
|
private IEnumerator CloseChestWithAnimation()
|
|
{
|
|
beingHandled = true;
|
|
// process pre-yield
|
|
yield return new WaitForSeconds( 0.2f );
|
|
m_Animator.SetTrigger("CloseIt");
|
|
yield return new WaitForSeconds( 0.1f );
|
|
m_Animator.ResetTrigger("CloseIt");
|
|
// process post-yield
|
|
beingHandled = false;
|
|
}
|
|
|
|
private void ReactivateAnimation()
|
|
{
|
|
m_Animator.SetTrigger("reactivate");
|
|
}
|
|
|
|
protected override void SetupPanel()
|
|
{
|
|
if(this.dynamicPanel)
|
|
{
|
|
this.dynamicPanel.GetComponent<ChestPanelController>().Setup(gameObject, _items);
|
|
}
|
|
}
|
|
// WARNING
|
|
// DANGER - functon override position which may be not free
|
|
|
|
}
|