2021-02-19 16:14:14 +01:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
2021-02-19 21:38:45 +01:00
|
|
|
using Ktyl.Util;
|
2021-02-23 14:05:42 +01:00
|
|
|
using UnityEngine.Events;
|
2021-02-19 16:14:14 +01:00
|
|
|
|
|
|
|
public class ArtefactControl : MonoBehaviour
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
private bool _show;
|
2021-02-25 15:21:35 +01:00
|
|
|
protected bool _canInteract;
|
2021-02-19 16:14:14 +01:00
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private Artefact data;
|
|
|
|
public int artefactID => _artefactID;
|
|
|
|
private int _artefactID;
|
2021-02-19 21:38:45 +01:00
|
|
|
[SerializeField] private SerialInt _nearbyArtefactID;
|
2021-02-19 16:14:14 +01:00
|
|
|
|
2021-02-23 14:05:42 +01:00
|
|
|
[SerializeField] private ArtefactSystem _artefacts;
|
|
|
|
|
2021-02-25 15:21:35 +01:00
|
|
|
protected virtual void Start()
|
2021-02-19 16:14:14 +01:00
|
|
|
{
|
|
|
|
_artefactID = data.artefactID;
|
|
|
|
_show = data.show;
|
|
|
|
_canInteract = data.canInteract;
|
|
|
|
|
|
|
|
EventHandler.current.onArtefactTriggerEnter += NearArtefact;
|
|
|
|
EventHandler.current.onArtefactTriggerExit += AwayArtefact;
|
|
|
|
EventHandler.current.onArtefactPickUp += PickUp;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void NearArtefact(int id)
|
|
|
|
{
|
|
|
|
if (id == this._artefactID)
|
|
|
|
{
|
|
|
|
_show = true;
|
|
|
|
this._canInteract = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void AwayArtefact(int id)
|
|
|
|
{
|
|
|
|
if (id == this._artefactID)
|
|
|
|
{
|
|
|
|
_show = false;
|
2021-02-25 15:21:35 +01:00
|
|
|
_canInteract = false;
|
2021-02-19 16:14:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-02-25 15:21:35 +01:00
|
|
|
protected virtual void PickUp(int id)
|
2021-02-19 16:14:14 +01:00
|
|
|
{
|
2021-02-25 15:21:35 +01:00
|
|
|
|
2021-02-19 16:14:14 +01:00
|
|
|
if (id == this._artefactID)
|
|
|
|
{
|
|
|
|
if (_canInteract == true)
|
|
|
|
{
|
2021-02-23 14:05:42 +01:00
|
|
|
// artefact system informs other systems about found artefact
|
|
|
|
_artefacts.FindArtefact(data);
|
2021-02-19 16:14:14 +01:00
|
|
|
}
|
2021-02-23 14:05:42 +01:00
|
|
|
|
2021-02-19 16:14:14 +01:00
|
|
|
if (this.gameObject != null)
|
2021-02-25 15:21:35 +01:00
|
|
|
{
|
2021-03-01 17:18:24 +01:00
|
|
|
data.Pickup();
|
2021-02-25 15:21:35 +01:00
|
|
|
_nearbyArtefactID.Value = -1;
|
|
|
|
_canInteract = false;
|
|
|
|
//_show = false;
|
2021-02-19 16:14:14 +01:00
|
|
|
Destroy(this.gameObject);
|
2021-02-25 15:21:35 +01:00
|
|
|
}
|
2021-02-19 16:14:14 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void OnGUI()
|
|
|
|
{
|
|
|
|
if (_show)
|
|
|
|
{
|
|
|
|
GUI.Label(new Rect(Screen.width / 2 - 50, 5, 100, 100), "Press E to pickup");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|