position tracking + scene switching
This commit is contained in:
2
Unity/.vscode/settings.json
vendored
2
Unity/.vscode/settings.json
vendored
@ -51,5 +51,5 @@
|
||||
"temp/": true,
|
||||
"Temp/": true
|
||||
},
|
||||
"dotnet.defaultSolution": "ConvaiTutor.sln"
|
||||
"dotnet.defaultSolution": "Unity.sln"
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
BIN
Unity/Assets/Scenes/AR/AR-Task1.unity
(Stored with Git LFS)
BIN
Unity/Assets/Scenes/AR/AR-Task1.unity
(Stored with Git LFS)
Binary file not shown.
BIN
Unity/Assets/Scenes/AR/AR-Task2.unity
(Stored with Git LFS)
BIN
Unity/Assets/Scenes/AR/AR-Task2.unity
(Stored with Git LFS)
Binary file not shown.
BIN
Unity/Assets/Scenes/AR/AR-Task3.unity
(Stored with Git LFS)
BIN
Unity/Assets/Scenes/AR/AR-Task3.unity
(Stored with Git LFS)
Binary file not shown.
BIN
Unity/Assets/Scenes/AR/AR-Task4.unity
(Stored with Git LFS)
BIN
Unity/Assets/Scenes/AR/AR-Task4.unity
(Stored with Git LFS)
Binary file not shown.
BIN
Unity/Assets/Scenes/Lobby.unity
(Stored with Git LFS)
BIN
Unity/Assets/Scenes/Lobby.unity
(Stored with Git LFS)
Binary file not shown.
@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eaebae442dddacd46b12d23e0f51dd89
|
||||
guid: b3b777d0fe1037047a86003d52277af0
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
|
||||
BIN
Unity/Assets/Scenes/VR/VR -Task2.unity
(Stored with Git LFS)
BIN
Unity/Assets/Scenes/VR/VR -Task2.unity
(Stored with Git LFS)
Binary file not shown.
BIN
Unity/Assets/Scenes/VR/VR -Task3.unity
(Stored with Git LFS)
BIN
Unity/Assets/Scenes/VR/VR -Task3.unity
(Stored with Git LFS)
Binary file not shown.
BIN
Unity/Assets/Scenes/VR/VR -Task4.unity
(Stored with Git LFS)
BIN
Unity/Assets/Scenes/VR/VR -Task4.unity
(Stored with Git LFS)
Binary file not shown.
BIN
Unity/Assets/Scenes/VR/VR-Task1.unity
(Stored with Git LFS)
BIN
Unity/Assets/Scenes/VR/VR-Task1.unity
(Stored with Git LFS)
Binary file not shown.
8
Unity/Assets/Scripts.meta
Normal file
8
Unity/Assets/Scripts.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f39dd68646df9ec4cb6fe2df126224c3
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
38
Unity/Assets/Scripts/ARVRMenu.cs
Normal file
38
Unity/Assets/Scripts/ARVRMenu.cs
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
146
Unity/Assets/Scripts/PositionTracker.cs
Normal file
146
Unity/Assets/Scripts/PositionTracker.cs
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
11
Unity/Assets/Scripts/PositionTracker.cs.meta
Normal file
11
Unity/Assets/Scripts/PositionTracker.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aff140421a156964d80dc8ff9a5d5960
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user