From 30594f0c65bdaf69978f111e51e4ddf416303e35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20S=C3=B6lder?= Date: Tue, 19 Aug 2025 16:52:10 +0200 Subject: [PATCH] Make time optional for Trackers Removes time from baseHeaders and RecordRow. This removes the dependency on Unity API in the base class, which allows RecordRow to be called outside the main tread. It also allows for non-time-based Trackers (e.g. frame count or event based). For the provided prototypes MouseScreenTracker, MouseWorldTracker and PositionRotationTracker, the timestamp is added in GetCurrentValues to provide the same functionality as before. --- Assets/UXF/Scripts/Etc/Tracker.cs | 3 +-- Assets/UXF/Scripts/Trackers/MouseScreenTracker.cs | 5 ++++- Assets/UXF/Scripts/Trackers/MouseWorldTracker.cs | 5 ++++- Assets/UXF/Scripts/Trackers/PositionRotationTracker.cs | 5 ++++- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Assets/UXF/Scripts/Etc/Tracker.cs b/Assets/UXF/Scripts/Etc/Tracker.cs index fe542cb1..faea84bd 100644 --- a/Assets/UXF/Scripts/Etc/Tracker.cs +++ b/Assets/UXF/Scripts/Etc/Tracker.cs @@ -12,7 +12,7 @@ namespace UXF /// public abstract class Tracker : MonoBehaviour { - private static string[] baseHeaders = new string[] { "time" }; + private static string[] baseHeaders = new string[] { }; private TrackerState currentState = TrackerState.Stopped; /// @@ -87,7 +87,6 @@ public void RecordRow() "Tracker measurements cannot be taken when not recording!"); UXFDataRow newRow = GetCurrentValues(); - newRow.Add(("time", Time.time)); Data.AddCompleteRow(newRow); } diff --git a/Assets/UXF/Scripts/Trackers/MouseScreenTracker.cs b/Assets/UXF/Scripts/Trackers/MouseScreenTracker.cs index ed86a0cf..f4df8aad 100644 --- a/Assets/UXF/Scripts/Trackers/MouseScreenTracker.cs +++ b/Assets/UXF/Scripts/Trackers/MouseScreenTracker.cs @@ -10,7 +10,7 @@ namespace UXF public class MouseScreenTracker : Tracker { public override string MeasurementDescriptor => "mouse_screen"; - public override IEnumerable CustomHeader => new string[] { "pix_x", "pix_y" }; + public override IEnumerable CustomHeader => new string[] { "time", "pix_x", "pix_y" }; /// /// Returns current mouse position in screen coordinates @@ -18,6 +18,8 @@ public class MouseScreenTracker : Tracker /// protected override UXFDataRow GetCurrentValues() { + float time = Time.time; + // get position and rotation Vector2 p = new Vector2(Input.mousePosition.x, Input.mousePosition.y); @@ -25,6 +27,7 @@ protected override UXFDataRow GetCurrentValues() // return position, rotation (x, y, z) as an array var values = new UXFDataRow() { + ("time", time), ("pix_x", p.x), ("pix_y", p.y) }; diff --git a/Assets/UXF/Scripts/Trackers/MouseWorldTracker.cs b/Assets/UXF/Scripts/Trackers/MouseWorldTracker.cs index 0ce6bd11..59f76029 100644 --- a/Assets/UXF/Scripts/Trackers/MouseWorldTracker.cs +++ b/Assets/UXF/Scripts/Trackers/MouseWorldTracker.cs @@ -16,7 +16,7 @@ public class MouseWorldTracker : Tracker public override string MeasurementDescriptor => "mouse_world"; - public override IEnumerable CustomHeader => new string[] { "pos_x", "pos_y", "pos_z", }; + public override IEnumerable CustomHeader => new string[] { "time", "pos_x", "pos_y", "pos_z", }; /// /// Returns current mouse position in world coordinates @@ -24,12 +24,15 @@ public class MouseWorldTracker : Tracker /// protected override UXFDataRow GetCurrentValues() { + float time = Time.time; + // get position and rotation Vector3 p = mainCamera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, distanceFromCamera)); // return position, rotation (x, y, z) as an array var values = new UXFDataRow() { + ("time", time), ("pos_x", p.x), ("pos_y", p.y), ("pos_z", p.z) diff --git a/Assets/UXF/Scripts/Trackers/PositionRotationTracker.cs b/Assets/UXF/Scripts/Trackers/PositionRotationTracker.cs index 034e6b97..d3736b0e 100644 --- a/Assets/UXF/Scripts/Trackers/PositionRotationTracker.cs +++ b/Assets/UXF/Scripts/Trackers/PositionRotationTracker.cs @@ -12,7 +12,7 @@ namespace UXF public class PositionRotationTracker : Tracker { public override string MeasurementDescriptor => "movement"; - public override IEnumerable CustomHeader => new string[] { "pos_x", "pos_y", "pos_z", "rot_x", "rot_y", "rot_z" }; + public override IEnumerable CustomHeader => new string[] { "time", "pos_x", "pos_y", "pos_z", "rot_x", "rot_y", "rot_z" }; /// /// Returns current position and rotation values @@ -20,6 +20,8 @@ public class PositionRotationTracker : Tracker /// protected override UXFDataRow GetCurrentValues() { + float time = Time.time; + // get position and rotation Vector3 p = gameObject.transform.position; Vector3 r = gameObject.transform.eulerAngles; @@ -27,6 +29,7 @@ protected override UXFDataRow GetCurrentValues() // return position, rotation (x, y, z) as an array var values = new UXFDataRow() { + ("time", time), ("pos_x", p.x), ("pos_y", p.y), ("pos_z", p.z),