2021-03-05 14:26:15 +01:00
|
|
|
using System;
|
2021-02-19 16:14:14 +01:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
2021-03-12 19:29:36 +01:00
|
|
|
using FMOD.Studio;
|
|
|
|
using Google.Apis.Http;
|
2021-02-19 16:14:14 +01:00
|
|
|
using UnityEngine;
|
2021-02-19 21:38:45 +01:00
|
|
|
using Ktyl.Util;
|
2021-03-12 18:15:27 +01:00
|
|
|
using TMPro;
|
2021-02-23 14:05:42 +01:00
|
|
|
using UnityEngine.Events;
|
2021-03-12 19:29:36 +01:00
|
|
|
using UnityEngine.InputSystem;
|
2021-02-19 16:14:14 +01:00
|
|
|
|
|
|
|
public class ArtefactControl : MonoBehaviour
|
|
|
|
{
|
2021-02-25 15:21:35 +01:00
|
|
|
protected bool _canInteract;
|
2021-02-19 16:14:14 +01:00
|
|
|
|
2021-03-02 17:33:31 +01:00
|
|
|
public Artefact data => _data;
|
|
|
|
[SerializeField] private Artefact _data;
|
2021-02-19 16:14:14 +01:00
|
|
|
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-03-05 14:26:15 +01:00
|
|
|
|
2021-03-12 19:29:36 +01:00
|
|
|
[SerializeField] private ArtefactInteractUI _ui;
|
2021-03-12 18:15:27 +01:00
|
|
|
|
2021-03-05 14:26:15 +01:00
|
|
|
private void OnEnable()
|
|
|
|
{
|
|
|
|
_artefacts.RegisterArtefact(_data);
|
2021-03-12 19:29:36 +01:00
|
|
|
SetNearby(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void SetNearby(bool playerNearby)
|
|
|
|
{
|
|
|
|
_canInteract = playerNearby;
|
|
|
|
_ui.gameObject.SetActive(playerNearby);
|
|
|
|
_nearbyArtefactID.Value = playerNearby ? artefactID : -1;
|
2021-03-05 14:26:15 +01:00
|
|
|
}
|
|
|
|
|
2021-02-25 15:21:35 +01:00
|
|
|
protected virtual void Start()
|
2021-02-19 16:14:14 +01:00
|
|
|
{
|
|
|
|
_artefactID = data.artefactID;
|
|
|
|
_canInteract = data.canInteract;
|
|
|
|
|
|
|
|
EventHandler.current.onArtefactPickUp += PickUp;
|
2021-03-12 18:15:27 +01:00
|
|
|
}
|
|
|
|
|
2021-03-12 19:29:36 +01:00
|
|
|
private void OnTriggerEnter(Collider other)
|
2021-02-19 16:14:14 +01:00
|
|
|
{
|
2021-03-12 19:29:36 +01:00
|
|
|
if (!other.gameObject.TryGetComponent(out PlayerInput playerInput))
|
2021-02-19 16:14:14 +01:00
|
|
|
{
|
2021-03-12 19:29:36 +01:00
|
|
|
Debug.LogError("collided with not the player ????", this);
|
|
|
|
return;
|
2021-02-19 16:14:14 +01:00
|
|
|
}
|
2021-03-12 19:29:36 +01:00
|
|
|
|
|
|
|
SetNearby(true);
|
|
|
|
|
|
|
|
_ui.Input = playerInput;
|
2021-02-19 16:14:14 +01:00
|
|
|
}
|
|
|
|
|
2021-03-12 19:29:36 +01:00
|
|
|
private void OnTriggerExit(Collider other)
|
2021-02-19 16:14:14 +01:00
|
|
|
{
|
2021-03-12 19:29:36 +01:00
|
|
|
SetNearby(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
|
|
|
{
|
|
|
|
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-03-02 19:20:23 +01:00
|
|
|
|
2021-02-25 15:21:35 +01:00
|
|
|
_nearbyArtefactID.Value = -1;
|
|
|
|
_canInteract = false;
|
2021-03-01 19:09:21 +01:00
|
|
|
EventHandler.current.ArtefactUI();
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|