96 lines
2.2 KiB
C#
96 lines
2.2 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using Ktyl.Util;
|
|
using UnityEngine.Events;
|
|
|
|
public class ArtefactControl : MonoBehaviour
|
|
{
|
|
private bool _show;
|
|
protected bool _canInteract;
|
|
|
|
private GUIStyle guiS = new GUIStyle();
|
|
|
|
public Artefact data => _data;
|
|
[SerializeField] private Artefact _data;
|
|
public int artefactID => _artefactID;
|
|
private int _artefactID;
|
|
[SerializeField] private SerialInt _nearbyArtefactID;
|
|
|
|
[SerializeField] private ArtefactSystem _artefacts;
|
|
|
|
private void OnEnable()
|
|
{
|
|
_artefacts.RegisterArtefact(_data);
|
|
}
|
|
|
|
protected virtual void Start()
|
|
{
|
|
_artefactID = data.artefactID;
|
|
_show = data.show;
|
|
_canInteract = data.canInteract;
|
|
|
|
EventHandler.current.onArtefactTriggerEnter += NearArtefact;
|
|
EventHandler.current.onArtefactTriggerExit += AwayArtefact;
|
|
EventHandler.current.onArtefactPickUp += PickUp;
|
|
|
|
guiS.fontSize = 22;
|
|
guiS.normal.textColor = Color.white;
|
|
guiS.alignment = TextAnchor.MiddleCenter;
|
|
}
|
|
|
|
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)
|
|
{
|
|
// artefact system informs other systems about found artefact
|
|
_artefacts.FindArtefact(data);
|
|
}
|
|
|
|
if (this.gameObject != null)
|
|
{
|
|
data.Pickup();
|
|
|
|
_nearbyArtefactID.Value = -1;
|
|
_canInteract = false;
|
|
EventHandler.current.ArtefactUI();
|
|
Destroy(this.gameObject);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
void OnGUI()
|
|
{
|
|
if (_show)
|
|
{
|
|
GUI.Label(new Rect(Screen.width / 2 - 50, 0, 100, 100), "Press E to pick up",guiS);
|
|
}
|
|
}
|
|
}
|