89 lines
2.3 KiB
C#
89 lines
2.3 KiB
C#
using UnityEngine;
|
||
using System.Collections.Generic;
|
||
using UnityEngine.XR;
|
||
using System.Collections;
|
||
|
||
public class EyesManager : MonoBehaviour
|
||
{
|
||
private static EyesManager _instance;
|
||
public static EyesManager GetInstance() => _instance;
|
||
|
||
public List<HallucinationsEye> allEyes = new List<HallucinationsEye>();
|
||
public Transform player;
|
||
|
||
[Header("Watch Settings")]
|
||
public float fieldOfViewAngle = 90f;
|
||
public float watchDistance = 10f;
|
||
|
||
private void Awake()
|
||
{
|
||
if (_instance == null)
|
||
_instance = this;
|
||
}
|
||
|
||
private void Start()
|
||
{
|
||
StartCoroutine(AfterGameLoaded());
|
||
}
|
||
|
||
IEnumerator AfterGameLoaded()
|
||
{
|
||
yield return new WaitUntil(() => LoadManager.GetInstance() != null && !LoadManager.GetInstance().LoadingGame);
|
||
yield return new WaitUntil(() => PlayerManager.GetInstance() != null);
|
||
player = PlayerManager.GetInstance().playerGameObj.transform;
|
||
//GetAllEyes();
|
||
}
|
||
|
||
private void Update()
|
||
{
|
||
foreach (HallucinationsEye eye in allEyes)
|
||
{
|
||
if (eye != null && eye.IsAlive)
|
||
{
|
||
eye.CheckPlayerVisibility(player, fieldOfViewAngle, watchDistance);
|
||
}
|
||
}
|
||
}
|
||
|
||
public bool IsPlayerWatched()
|
||
{
|
||
foreach (HallucinationsEye eye in allEyes)
|
||
{
|
||
if (eye != null && eye.IsWatching)
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
public void RegisterEye(HallucinationsEye eye)
|
||
{
|
||
if (!allEyes.Contains(eye))
|
||
allEyes.Add(eye);
|
||
Debug.Log("Registered Eye: " + eye.name);
|
||
}
|
||
|
||
public void UnregisterEye(HallucinationsEye eye)
|
||
{
|
||
if (allEyes.Contains(eye))
|
||
allEyes.Remove(eye);
|
||
Debug.Log("UnregisterEye Eye: " + eye.name);
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// Επιστρέφει true αν στο δεδομένο GameObject υπάρχει έστω ένα ζωντανό μάτι.
|
||
/// </summary>
|
||
public bool IsAnyEyeAliveOn(GameObject go)
|
||
{
|
||
var eyes = go.GetComponentsInChildren<HallucinationsEye>();
|
||
foreach (var e in eyes)
|
||
if (e.IsAlive) return true;
|
||
return false;
|
||
}
|
||
|
||
public List<HallucinationsEye> GetAllEyes()
|
||
{
|
||
return allEyes; // Υποθέτουμε ότι τα αποθηκεύεις
|
||
}
|
||
}
|