70 lines
2.7 KiB
C#
70 lines
2.7 KiB
C#
using Cysharp.Threading.Tasks;
|
|
using GhostSystem;
|
|
using NUnit.Framework;
|
|
using UnityEngine;
|
|
|
|
// Dieses Script übernimmt die eigentliche Auswertung des Eyetrackings per Raycast.
|
|
|
|
public class EyeTrackingCollisionPoints : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private float rayDistance = 1.0f;
|
|
|
|
[SerializeField]
|
|
private LayerMask gazableLayers;
|
|
[SerializeField]
|
|
private LayerMask targetLayers;
|
|
|
|
public GameObject hitPointPrefab;
|
|
|
|
public GameObject hitPoint;
|
|
|
|
public bool heatIsActive = false;
|
|
|
|
private void FixedUpdate()
|
|
{
|
|
RaycastHit hit;
|
|
|
|
Vector3 rayCastDirection = transform.TransformDirection(Vector3.forward) * rayDistance;
|
|
|
|
if ( hitPoint != null && Physics.Raycast(transform.position, rayCastDirection, out hit, rayDistance, gazableLayers)) // Sendet einen Raycast in Blickrichtung aus.
|
|
{
|
|
hitPoint.transform.position = new Vector3(hit.point.x, hit.point.y, hit.point.z); // Wenn ein Objekt mit der passenden Layer Mask getroffen wurde, wird der Gazepoint
|
|
// in der Visualisierung auf die entsprechende Kollisionsposition gesetzt.
|
|
if (heatIsActive) // Ist die Heat-Visualisierung (rote Färbung der Target-Objekte) aktiviert,
|
|
{
|
|
FindVisibleTargets(hitPoint.transform.position); // wird noch einmal mit einem Radius von 20 cm im Umfeld des Hitpoints nach
|
|
} // Objekten gesucht, die gefärbt werden können.
|
|
|
|
}
|
|
}
|
|
|
|
public Transform SpawnHitPoint() // Wird durch LocalPlayerReferences aufgerufen, um nicht zu oft den GhostRecorder zu suchen.
|
|
{
|
|
hitPoint = Instantiate(hitPointPrefab);
|
|
return hitPoint.transform;
|
|
}
|
|
|
|
void FindVisibleTargets(Vector3 hitPosition) // Sucht in einem Radius von 20 cm um den HitPoint nach Targets
|
|
{
|
|
Collider[] visibleTargets = Physics.OverlapSphere(hitPosition, 0.2f, targetLayers);
|
|
foreach (Collider col in visibleTargets)
|
|
{
|
|
GameObject hitObject = col.gameObject;
|
|
if (hitObject.GetComponent<RecieveHeat>() != null)
|
|
{
|
|
hitObject.GetComponent<RecieveHeat>().AddHeat(0.02f); // Jedes Mal, wenn ein passendes Objekt getroffen wird, wird desen Heat-Wert um 0,02 erhöht.
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("Hit " + hitObject.name);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void IsHeatActive(bool heatActive)
|
|
{
|
|
heatIsActive = heatActive;
|
|
}
|
|
}
|
|
|