2022-05-04 10:18:58 +01:00
|
|
|
|
using QSB.EyeOfTheUniverse.Tomb.Messages;
|
|
|
|
|
using QSB.Messaging;
|
|
|
|
|
using QSB.Player;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace QSB.EyeOfTheUniverse.Tomb;
|
|
|
|
|
|
|
|
|
|
internal class EyeTombWatcher : MonoBehaviour
|
|
|
|
|
{
|
2022-08-17 17:11:53 -07:00
|
|
|
|
private EyeTombController _tomb;
|
2022-05-04 10:18:58 +01:00
|
|
|
|
|
2022-08-17 17:11:53 -07:00
|
|
|
|
private void Awake()
|
2022-05-04 10:18:58 +01:00
|
|
|
|
{
|
2022-08-17 17:11:53 -07:00
|
|
|
|
_tomb = GetComponent<EyeTombController>();
|
|
|
|
|
_tomb._graveObserveTrigger.OnGainFocus += OnObserveGrave;
|
|
|
|
|
enabled = false;
|
2022-05-04 10:18:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
2022-08-17 17:11:53 -07:00
|
|
|
|
private void OnDestroy() =>
|
|
|
|
|
_tomb._graveObserveTrigger.OnGainFocus -= OnObserveGrave;
|
2022-05-04 10:18:58 +01:00
|
|
|
|
|
|
|
|
|
private void OnObserveGrave()
|
|
|
|
|
{
|
2022-08-17 17:11:53 -07:00
|
|
|
|
_tomb._graveObserveTrigger.OnGainFocus -= OnObserveGrave;
|
|
|
|
|
enabled = true;
|
2022-05-04 10:18:58 +01:00
|
|
|
|
}
|
2022-08-17 17:11:53 -07:00
|
|
|
|
|
2022-05-04 10:18:58 +01:00
|
|
|
|
private void FixedUpdate()
|
|
|
|
|
{
|
|
|
|
|
var canShowStage = true;
|
|
|
|
|
foreach (var player in QSBPlayerManager.PlayerList)
|
|
|
|
|
{
|
2022-08-17 17:11:53 -07:00
|
|
|
|
var playerToStage = _tomb._stageRoot.transform.position - player.Body.transform.position;
|
2022-05-04 10:18:58 +01:00
|
|
|
|
var playerLookDirection = player.Body.transform.forward;
|
|
|
|
|
var angle = Vector3.Angle(playerLookDirection, playerToStage);
|
|
|
|
|
if (angle < 70)
|
|
|
|
|
{
|
|
|
|
|
canShowStage = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (canShowStage)
|
|
|
|
|
{
|
2022-08-17 17:11:53 -07:00
|
|
|
|
_tomb._stageRoot.SetActive(true);
|
2022-05-04 10:18:58 +01:00
|
|
|
|
new ShowStageMessage().Send();
|
2022-08-17 17:11:53 -07:00
|
|
|
|
Destroy(this);
|
2022-05-04 10:18:58 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|