From 568be7e6287fd8235e2d6ef1c585486227ac48fa Mon Sep 17 00:00:00 2001 From: "tom.hempel" Date: Sun, 12 Oct 2025 14:14:02 +0200 Subject: [PATCH] position tracking + scene switching --- Unity/.vscode/settings.json | 2 +- Unity/Assets/ARVRMenu.cs | 33 ----- Unity/Assets/Scenes/AR/AR-Task1.unity | 4 +- Unity/Assets/Scenes/AR/AR-Task2.unity | 4 +- Unity/Assets/Scenes/AR/AR-Task3.unity | 4 +- Unity/Assets/Scenes/AR/AR-Task4.unity | 4 +- Unity/Assets/Scenes/Lobby.unity | 4 +- Unity/Assets/Scenes/Lobby.unity.meta | 2 +- Unity/Assets/Scenes/VR/VR -Task2.unity | 4 +- Unity/Assets/Scenes/VR/VR -Task3.unity | 4 +- Unity/Assets/Scenes/VR/VR -Task4.unity | 4 +- Unity/Assets/Scenes/VR/VR-Task1.unity | 4 +- Unity/Assets/Scripts.meta | 8 + Unity/Assets/Scripts/ARVRMenu.cs | 38 +++++ Unity/Assets/{ => Scripts}/ARVRMenu.cs.meta | 0 Unity/Assets/Scripts/PositionTracker.cs | 146 +++++++++++++++++++ Unity/Assets/Scripts/PositionTracker.cs.meta | 11 ++ 17 files changed, 223 insertions(+), 53 deletions(-) delete mode 100644 Unity/Assets/ARVRMenu.cs create mode 100644 Unity/Assets/Scripts.meta create mode 100644 Unity/Assets/Scripts/ARVRMenu.cs rename Unity/Assets/{ => Scripts}/ARVRMenu.cs.meta (100%) create mode 100644 Unity/Assets/Scripts/PositionTracker.cs create mode 100644 Unity/Assets/Scripts/PositionTracker.cs.meta diff --git a/Unity/.vscode/settings.json b/Unity/.vscode/settings.json index 4c25bb8..9636283 100644 --- a/Unity/.vscode/settings.json +++ b/Unity/.vscode/settings.json @@ -51,5 +51,5 @@ "temp/": true, "Temp/": true }, - "dotnet.defaultSolution": "ConvaiTutor.sln" + "dotnet.defaultSolution": "Unity.sln" } \ No newline at end of file diff --git a/Unity/Assets/ARVRMenu.cs b/Unity/Assets/ARVRMenu.cs deleted file mode 100644 index ff34ed7..0000000 --- a/Unity/Assets/ARVRMenu.cs +++ /dev/null @@ -1,33 +0,0 @@ -using UnityEngine; -using UnityEngine.UI; -using UnityEngine.SceneManagement; - -public class TaskButtonManager : MonoBehaviour -{ - [System.Serializable] - public class TaskButton - { - public Button button; - public int sceneIndex; - } - - [Header("Assign buttons with their scene indexes")] - public TaskButton[] taskButtons; - - private void Start() - { - foreach (var tb in taskButtons) - { - if (tb.button != null) - { - int index = tb.sceneIndex; // capture local copy for lambda - tb.button.onClick.AddListener(() => LoadScene(index)); - } - } - } - - private void LoadScene(int index) - { - SceneManager.LoadScene(index); - } -} diff --git a/Unity/Assets/Scenes/AR/AR-Task1.unity b/Unity/Assets/Scenes/AR/AR-Task1.unity index c358cb0..770641e 100644 --- a/Unity/Assets/Scenes/AR/AR-Task1.unity +++ b/Unity/Assets/Scenes/AR/AR-Task1.unity @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d50d87bbba0ed339526577547113a7839262ad255a8b2de61bb400acb776285a -size 52762 +oid sha256:e286b218eec091bce4bb95190b40ee739aae30605926d524b14ce1cfdd8ce997 +size 54374 diff --git a/Unity/Assets/Scenes/AR/AR-Task2.unity b/Unity/Assets/Scenes/AR/AR-Task2.unity index 550458c..4df4d8d 100644 --- a/Unity/Assets/Scenes/AR/AR-Task2.unity +++ b/Unity/Assets/Scenes/AR/AR-Task2.unity @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9dc28ae225d28aaa7b2ddd883e6738d2f868de93f5b93a54caed1c9aab99e9ee -size 157594 +oid sha256:6139c2517920c1f0a1a8d717f5cd4304b2ee45f0c6f8ece3f427fff63f68c31b +size 59323 diff --git a/Unity/Assets/Scenes/AR/AR-Task3.unity b/Unity/Assets/Scenes/AR/AR-Task3.unity index 550458c..7c6472f 100644 --- a/Unity/Assets/Scenes/AR/AR-Task3.unity +++ b/Unity/Assets/Scenes/AR/AR-Task3.unity @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9dc28ae225d28aaa7b2ddd883e6738d2f868de93f5b93a54caed1c9aab99e9ee -size 157594 +oid sha256:609b300cd18fef5161ba8c4ddcf795249f95d1a2dd6db9d45c124891cc14f58b +size 59331 diff --git a/Unity/Assets/Scenes/AR/AR-Task4.unity b/Unity/Assets/Scenes/AR/AR-Task4.unity index 550458c..6584ca7 100644 --- a/Unity/Assets/Scenes/AR/AR-Task4.unity +++ b/Unity/Assets/Scenes/AR/AR-Task4.unity @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9dc28ae225d28aaa7b2ddd883e6738d2f868de93f5b93a54caed1c9aab99e9ee -size 157594 +oid sha256:fda8b00122d0649e04401d330751e7198ebe066be45ed83f78075ac9e18c9425 +size 59331 diff --git a/Unity/Assets/Scenes/Lobby.unity b/Unity/Assets/Scenes/Lobby.unity index 5b3ee22..c65d20c 100644 --- a/Unity/Assets/Scenes/Lobby.unity +++ b/Unity/Assets/Scenes/Lobby.unity @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:02715fe0dfbc20100111348623e22f77ca5f79d77129233744eed0128e64760d -size 112178 +oid sha256:77e41cddbb03ae4a79dfd45c492f1aa2e195f8a5a82c0e6a9b8edb0003b36488 +size 4610710 diff --git a/Unity/Assets/Scenes/Lobby.unity.meta b/Unity/Assets/Scenes/Lobby.unity.meta index b28fa4d..c7785d0 100644 --- a/Unity/Assets/Scenes/Lobby.unity.meta +++ b/Unity/Assets/Scenes/Lobby.unity.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: eaebae442dddacd46b12d23e0f51dd89 +guid: b3b777d0fe1037047a86003d52277af0 DefaultImporter: externalObjects: {} userData: diff --git a/Unity/Assets/Scenes/VR/VR -Task2.unity b/Unity/Assets/Scenes/VR/VR -Task2.unity index 43983e4..bac84d8 100644 --- a/Unity/Assets/Scenes/VR/VR -Task2.unity +++ b/Unity/Assets/Scenes/VR/VR -Task2.unity @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a863ab8900a61bc5c83fd69e6ecc6574fe0ffa2d88fce9cface60cc9f38ecd44 -size 4627914 +oid sha256:6e72fe9e2f613f0d2703c1126acf39ff1bd26a482b3bcc710627ce82c2bed16a +size 4628783 diff --git a/Unity/Assets/Scenes/VR/VR -Task3.unity b/Unity/Assets/Scenes/VR/VR -Task3.unity index 43983e4..2e38953 100644 --- a/Unity/Assets/Scenes/VR/VR -Task3.unity +++ b/Unity/Assets/Scenes/VR/VR -Task3.unity @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a863ab8900a61bc5c83fd69e6ecc6574fe0ffa2d88fce9cface60cc9f38ecd44 -size 4627914 +oid sha256:8fa0490c557f98924eff1688d643a8311d8ca0edd8eb6826c31185f8cfd8f82a +size 4628781 diff --git a/Unity/Assets/Scenes/VR/VR -Task4.unity b/Unity/Assets/Scenes/VR/VR -Task4.unity index 43983e4..e2bd977 100644 --- a/Unity/Assets/Scenes/VR/VR -Task4.unity +++ b/Unity/Assets/Scenes/VR/VR -Task4.unity @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a863ab8900a61bc5c83fd69e6ecc6574fe0ffa2d88fce9cface60cc9f38ecd44 -size 4627914 +oid sha256:dd700e3b5b4c7b9dcbcde908d1801af245fd2a2adc62672105dd763d0cb4a327 +size 4628781 diff --git a/Unity/Assets/Scenes/VR/VR-Task1.unity b/Unity/Assets/Scenes/VR/VR-Task1.unity index 7f833b9..a8a5496 100644 --- a/Unity/Assets/Scenes/VR/VR-Task1.unity +++ b/Unity/Assets/Scenes/VR/VR-Task1.unity @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6d8daa35c7cb428e79f5004b733634c6228cfeb3751858a0df7c7b4f709f2b2f -size 4627194 +oid sha256:1bb7817ffff2e1e15217f05750ecb87e3716478d491a12b5e57e1db34cedf6fd +size 4628788 diff --git a/Unity/Assets/Scripts.meta b/Unity/Assets/Scripts.meta new file mode 100644 index 0000000..1458572 --- /dev/null +++ b/Unity/Assets/Scripts.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f39dd68646df9ec4cb6fe2df126224c3 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Unity/Assets/Scripts/ARVRMenu.cs b/Unity/Assets/Scripts/ARVRMenu.cs new file mode 100644 index 0000000..7605a56 --- /dev/null +++ b/Unity/Assets/Scripts/ARVRMenu.cs @@ -0,0 +1,38 @@ +using UnityEngine; +using UnityEngine.SceneManagement; + +public class TaskButtonManager : MonoBehaviour +{ + private void Update() + { + // VR Tasks (Keys 1-4) + if (Input.GetKeyDown(KeyCode.Alpha1) || Input.GetKeyDown(KeyCode.Keypad1)) + LoadSceneByName("VR-Task1"); + else if (Input.GetKeyDown(KeyCode.Alpha2) || Input.GetKeyDown(KeyCode.Keypad2)) + LoadSceneByName("VR -Task2"); + else if (Input.GetKeyDown(KeyCode.Alpha3) || Input.GetKeyDown(KeyCode.Keypad3)) + LoadSceneByName("VR -Task3"); + else if (Input.GetKeyDown(KeyCode.Alpha4) || Input.GetKeyDown(KeyCode.Keypad4)) + LoadSceneByName("VR -Task4"); + + // AR Tasks (Keys 5-8) + else if (Input.GetKeyDown(KeyCode.Alpha5) || Input.GetKeyDown(KeyCode.Keypad5)) + LoadSceneByName("AR-Task1"); + else if (Input.GetKeyDown(KeyCode.Alpha6) || Input.GetKeyDown(KeyCode.Keypad6)) + LoadSceneByName("AR-Task2"); + else if (Input.GetKeyDown(KeyCode.Alpha7) || Input.GetKeyDown(KeyCode.Keypad7)) + LoadSceneByName("AR-Task3"); + else if (Input.GetKeyDown(KeyCode.Alpha8) || Input.GetKeyDown(KeyCode.Keypad8)) + LoadSceneByName("AR-Task4"); + + // Lobby (Key L or 0) + else if (Input.GetKeyDown(KeyCode.L) || Input.GetKeyDown(KeyCode.Alpha0) || Input.GetKeyDown(KeyCode.Keypad0)) + LoadSceneByName("Lobby"); + } + + private void LoadSceneByName(string sceneName) + { + Debug.Log($"Loading scene: {sceneName}"); + SceneManager.LoadScene(sceneName); + } +} diff --git a/Unity/Assets/ARVRMenu.cs.meta b/Unity/Assets/Scripts/ARVRMenu.cs.meta similarity index 100% rename from Unity/Assets/ARVRMenu.cs.meta rename to Unity/Assets/Scripts/ARVRMenu.cs.meta diff --git a/Unity/Assets/Scripts/PositionTracker.cs b/Unity/Assets/Scripts/PositionTracker.cs new file mode 100644 index 0000000..8e51f20 --- /dev/null +++ b/Unity/Assets/Scripts/PositionTracker.cs @@ -0,0 +1,146 @@ +using UnityEngine; +using System.IO; +using System.Text; +using System; + +public class PositionTracker : MonoBehaviour +{ + [Header("Objects to Track")] + [Tooltip("First object to track position")] + public Transform object1; + + [Tooltip("Second object to track position")] + public Transform object2; + + [Header("Tracking Settings")] + [Tooltip("How often to record positions (in seconds)")] + public float recordInterval = 0.1f; + + [Tooltip("Custom filename (without extension). Leave empty for auto-generated name")] + public string customFileName = ""; + + [Tooltip("Start tracking automatically on scene load")] + public bool autoStart = true; + + private string filePath; + private float timer; + private bool isTracking; + private StreamWriter writer; + private int frameCount; + + private void Start() + { + if (autoStart) + { + StartTracking(); + } + } + + public void StartTracking() + { + if (object1 == null || object2 == null) + { + Debug.LogError("PositionTracker: Both objects must be assigned in the inspector!"); + return; + } + + // Generate filename with timestamp + string timestamp = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"); + string fileName = string.IsNullOrEmpty(customFileName) + ? $"PositionData_{timestamp}.csv" + : $"{customFileName}_{timestamp}.csv"; + + filePath = Path.Combine(Application.persistentDataPath, fileName); + + try + { + // Create and open the file + writer = new StreamWriter(filePath, false, Encoding.UTF8); + + // Write CSV header + writer.WriteLine("Timestamp,Frame,Object1_Name,Object1_X,Object1_Y,Object1_Z,Object2_Name,Object2_X,Object2_Y,Object2_Z"); + + isTracking = true; + frameCount = 0; + timer = 0f; + + Debug.Log($"PositionTracker: Started tracking. Data will be saved to: {filePath}"); + } + catch (Exception e) + { + Debug.LogError($"PositionTracker: Failed to create CSV file. Error: {e.Message}"); + } + } + + public void StopTracking() + { + if (isTracking && writer != null) + { + writer.Close(); + isTracking = false; + Debug.Log($"PositionTracker: Stopped tracking. Data saved to: {filePath}"); + } + } + + private void Update() + { + if (!isTracking || writer == null) + return; + + timer += Time.deltaTime; + + if (timer >= recordInterval) + { + RecordPositions(); + timer = 0f; + } + + // Press 'T' to toggle tracking, 'S' to stop and save + if (Input.GetKeyDown(KeyCode.T)) + { + if (isTracking) + StopTracking(); + else + StartTracking(); + } + } + + private void RecordPositions() + { + if (object1 == null || object2 == null) + return; + + frameCount++; + + Vector3 pos1 = object1.position; + Vector3 pos2 = object2.position; + + string timestamp = DateTime.Now.ToString("HH:mm:ss.fff"); + + // Write data row + string dataRow = $"{timestamp},{frameCount}," + + $"{object1.name},{pos1.x:F4},{pos1.y:F4},{pos1.z:F4}," + + $"{object2.name},{pos2.x:F4},{pos2.y:F4},{pos2.z:F4}"; + + writer.WriteLine(dataRow); + writer.Flush(); // Ensure data is written immediately + } + + private void OnDestroy() + { + StopTracking(); + } + + private void OnApplicationQuit() + { + StopTracking(); + } + + // Helper method to open the folder containing the CSV file + [ContextMenu("Open Data Folder")] + public void OpenDataFolder() + { + Application.OpenURL(Application.persistentDataPath); + } +} + diff --git a/Unity/Assets/Scripts/PositionTracker.cs.meta b/Unity/Assets/Scripts/PositionTracker.cs.meta new file mode 100644 index 0000000..8d8780a --- /dev/null +++ b/Unity/Assets/Scripts/PositionTracker.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: aff140421a156964d80dc8ff9a5d5960 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: