Working EyeTracking with moving Hitpoint

This commit is contained in:
Thorbjoern
2025-06-02 19:26:42 +02:00
parent a5f152a23f
commit 0cb48fe1a9
17 changed files with 10909 additions and 692 deletions
@@ -0,0 +1,35 @@
using Cysharp.Threading.Tasks;
using GhostSystem;
using NUnit.Framework;
using UnityEngine;
public class EyeTrackingCollisionPoints : MonoBehaviour
{
[SerializeField]
private float rayDistance = 1.0f;
[SerializeField]
private LayerMask layersToInclude;
public GameObject hitPointPrefab;
private GameObject hitPoint;
private void FixedUpdate()
{
RaycastHit hit;
Vector3 rayCastDirection = transform.TransformDirection(Vector3.forward) * rayDistance;
if ( hitPoint != null && Physics.Raycast(transform.position, rayCastDirection, out hit, rayDistance, layersToInclude))
{
hitPoint.transform.position = new Vector3(hit.point.x, hit.point.y, hit.point.z);
}
}
public Transform SpawnHitPoint() // Wird durch LocalPlayerReferences aufgerufen, um nicht zu oft den GhostRecorder zu suchen.
{
hitPoint = Instantiate(hitPointPrefab);
return hitPoint.transform;
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 333c9f69cc49e564ba4816a87e7255bb
@@ -15,10 +15,12 @@ namespace GhostSystem
public List<Transform> TrackedObjects;
private float _timer;
private bool _isRecording;
public bool _isRecording;
private bool supabaseReady = false;
private bool sceneIdReady = false;
public static event Action OnRecord;
public static event Action OnStopRecord;
private async void OnEnable()
{
@@ -95,6 +97,7 @@ namespace GhostSystem
{
if (!supabaseReady || !sceneIdReady) return;
_isRecording = true;
OnRecord?.Invoke();
Debug.Log($"Recording {SceneId}");
}
@@ -102,6 +105,7 @@ namespace GhostSystem
{
_isRecording = false;
sceneIdReady = false;
OnStopRecord?.Invoke();
Debug.Log($"Stop recording: {SceneId}");
}
@@ -1,5 +1,6 @@
using GhostSystem;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using Unity.Netcode;
using UnityEngine;
@@ -10,6 +11,9 @@ public class LocalPlayerReference : NetworkBehaviour
public List<Transform> myObjects;
public EyeTrackingCollisionPoints collisionPoints;
public static event Action OnPlayerReady;
public override void OnNetworkSpawn()
{
if (IsOwner)
@@ -27,6 +31,9 @@ public class LocalPlayerReference : NetworkBehaviour
ghostRecorder.TrackedObjects.Add(obj);
}
}
ghostRecorder.TrackedObjects.Add(collisionPoints.SpawnHitPoint());
OnPlayerReady?.Invoke();
Debug.LogError("Invoked OnPlayerReady");
}
}
@@ -42,8 +42,10 @@ public class OVRStickAndRoomscaleMovement : NetworkBehaviour
characterController.center = new Vector3(headLocalPos.x, height / 2f + characterController.skinWidth, headLocalPos.z);
// 4. Stick Movement
Vector2 input = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick);
Vector3 move = cameraTransform.forward * input.y + cameraTransform.right * input.x;
Vector2 inputPos = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick);
Vector2 inputRot = OVRInput.Get(OVRInput.Axis2D.SecondaryThumbstick);
Vector3 move = cameraTransform.forward * inputPos.y + cameraTransform.right * inputPos.x;
move.y = 0;
move.Normalize();
+47
View File
@@ -0,0 +1,47 @@
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using GhostSystem;
public class VRDebugger : MonoBehaviour
{
public TMP_Text trackedObjects;
public TMP_Text recording;
public EyeTrackingCollisionPoints collisionPoints;
private void OnEnable()
{
LocalPlayerReference.OnPlayerReady += GetTrackedObjects;
GhostRecorderBatch.OnRecord += RecordingStart;
GhostRecorderBatch.OnStopRecord += RecordingStop;
}
private void OnDisable()
{
LocalPlayerReference.OnPlayerReady -= GetTrackedObjects;
GhostRecorderBatch.OnRecord -= RecordingStart;
GhostRecorderBatch.OnStopRecord -= RecordingStop;
}
private void GetTrackedObjects()
{
GhostRecorderBatch ghostRecorder = FindFirstObjectByType<GhostRecorderBatch>();
foreach (var obj in ghostRecorder.TrackedObjects)
{
trackedObjects.text += "\n\r" + obj;
}
}
private void RecordingStart()
{
recording.color = Color.white;
recording.text = "Recording...";
}
private void RecordingStop()
{
recording.color = Color.white;
recording.text = "...";
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 453b0f3c2406dc34dab9b42b8d2eb386