89 lines
2.1 KiB
C#
89 lines
2.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using Ktyl.Util;
|
|
|
|
public class ArtefactControl : MonoBehaviour
|
|
{
|
|
|
|
|
|
private bool _show;
|
|
protected bool _canInteract;
|
|
|
|
public Artefact data => _data;
|
|
[SerializeField] private Artefact _data;
|
|
public int artefactID => _artefactID;
|
|
private int _artefactID;
|
|
private string _artefactDialogue;
|
|
[SerializeField] private SerialInt _nearbyArtefactID;
|
|
|
|
protected virtual void Awake()
|
|
{
|
|
_artefactID = _data.artefactID;
|
|
_artefactDialogue = _data.artefactDialogue;
|
|
_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;
|
|
_canInteract = false;
|
|
}
|
|
|
|
}
|
|
|
|
protected virtual void PickUp(int id)
|
|
{
|
|
|
|
if (id == this._artefactID)
|
|
{
|
|
if (_canInteract == true)
|
|
{
|
|
ArtefactInventory.addA(_data);
|
|
//debug ArtefactInventory
|
|
//foreach (var x in ArtefactInventory.artefactList)
|
|
//{
|
|
// Debug.Log(x.ToString());
|
|
//}
|
|
|
|
}
|
|
//here put 'show artifact dialogue'
|
|
if (this.gameObject != null)
|
|
{
|
|
_data.PowerUnlock();
|
|
_nearbyArtefactID.Value = -1;
|
|
_canInteract = false;
|
|
EventHandler.current.ArtefactUI();
|
|
Destroy(this.gameObject);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
void OnGUI()
|
|
{
|
|
if (_show)
|
|
{
|
|
GUI.Label(new Rect(Screen.width / 2 - 50, 5, 100, 100), "Press E to pickup");
|
|
}
|
|
}
|
|
}
|