Wszystkie funkcjonalnosci git, potrzeba poprawy UI
This commit is contained in:
64
Assets/Scripts/PlayerTracker.cs
Normal file
64
Assets/Scripts/PlayerTracker.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using UnityEngine;
|
||||
using System.IO;
|
||||
using System;
|
||||
|
||||
public class PlayerTracker : MonoBehaviour
|
||||
{
|
||||
[Header("Tracking Settings")]
|
||||
[Tooltip("Przeci¹gnij tutaj Main Camera ze swojego gracza VR")]
|
||||
public Transform vrCamera;
|
||||
[Tooltip("Jak czêsto zapisywaæ dane? (0.2 = 5 razy na sekundê)")]
|
||||
public float recordInterval = 0.2f;
|
||||
|
||||
private string trackingFilePath;
|
||||
private float timer;
|
||||
|
||||
void Start()
|
||||
{
|
||||
// Sprawdzamy, czy Mened¿er jest aktywny i prosimy go o œcie¿kê
|
||||
if (ExperimentManager.Instance != null)
|
||||
{
|
||||
string folderPath = ExperimentManager.Instance.GetCurrentFolderPath();
|
||||
|
||||
if (!string.IsNullOrEmpty(folderPath))
|
||||
{
|
||||
// Tworzymy nazwê pliku z dat¹ i godzin¹
|
||||
string phaseName = new DirectoryInfo(folderPath).Name;
|
||||
string fileName = $"{phaseName}_Tracking_{DateTime.Now:yyyyMMdd_HHmmss}.csv";
|
||||
trackingFilePath = Path.Combine(folderPath, fileName);
|
||||
|
||||
// Tworzymy plik i nag³ówki kolumn
|
||||
File.WriteAllText(trackingFilePath, "Timestamp;PosX;PosY;PosZ;RotX;RotY;RotZ\n");
|
||||
Debug.Log($"[PlayerTracker] Zaczynam œledzenie! Zapis do: {fileName}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
// Jeœli nie mamy pliku albo kamery, nic nie robimy
|
||||
if (string.IsNullOrEmpty(trackingFilePath) || vrCamera == null) return;
|
||||
|
||||
// Odliczamy czas
|
||||
timer += Time.deltaTime;
|
||||
if (timer >= recordInterval)
|
||||
{
|
||||
timer = 0f;
|
||||
LogPosition();
|
||||
}
|
||||
}
|
||||
|
||||
private void LogPosition()
|
||||
{
|
||||
string timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
|
||||
Vector3 pos = vrCamera.position;
|
||||
Vector3 rot = vrCamera.eulerAngles; // Rotacja w stopniach (0-360)
|
||||
|
||||
// U¿ywamy InvariantCulture, by zawsze wymusiæ kropkê jako separator dziesiêtny zamiast przecinka
|
||||
string line = string.Format(System.Globalization.CultureInfo.InvariantCulture,
|
||||
"{0};{1:F3};{2:F3};{3:F3};{4:F3};{5:F3};{6:F3}\n",
|
||||
timestamp, pos.x, pos.y, pos.z, rot.x, rot.y, rot.z);
|
||||
|
||||
File.AppendAllText(trackingFilePath, line);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user