Wszystkie funkcjonalnosci git, potrzeba poprawy UI
This commit is contained in:
181
Assets/Scripts/ExperimentManager.cs
Normal file
181
Assets/Scripts/ExperimentManager.cs
Normal file
@@ -0,0 +1,181 @@
|
||||
using UnityEngine;
|
||||
using MQTTnet;
|
||||
using MQTTnet.Client;
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
[Serializable]
|
||||
public class SensorData
|
||||
{
|
||||
public float hr;
|
||||
public float gsr;
|
||||
}
|
||||
|
||||
public class ExperimentManager : MonoBehaviour
|
||||
{
|
||||
public static ExperimentManager Instance;
|
||||
|
||||
[Header("MQTT Settings")]
|
||||
public string brokerIp = "127.0.0.1";
|
||||
public int port = 1883;
|
||||
public string topic = "m5stick/state";
|
||||
|
||||
[Header("Watchdog Settings")]
|
||||
public float timeoutSeconds = 5f; // Czas w sekundach do w³¹czenia alarmu
|
||||
|
||||
private IMqttClient _mqttClient;
|
||||
private string _subjectFolderPath;
|
||||
private string _currentCsvFilePath;
|
||||
|
||||
private ConcurrentQueue<SensorData> _dataQueue = new ConcurrentQueue<SensorData>();
|
||||
|
||||
// Zmienne do pilnowania czasu
|
||||
private float _timeSinceLastMessage = 0f;
|
||||
private bool _isDataTimeoutWarningShown = false;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (Instance == null)
|
||||
{
|
||||
Instance = this;
|
||||
DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
public async void InitializeSession(string subjectId)
|
||||
{
|
||||
string dataPath = Path.Combine(Application.dataPath, "Data");
|
||||
_subjectFolderPath = Path.Combine(dataPath, subjectId);
|
||||
|
||||
Directory.CreateDirectory(_subjectFolderPath);
|
||||
Directory.CreateDirectory(Path.Combine(_subjectFolderPath, "Neutral"));
|
||||
Directory.CreateDirectory(Path.Combine(_subjectFolderPath, "Experimental"));
|
||||
|
||||
Debug.Log($"[ExperimentManager] Folders created for subject: {subjectId}");
|
||||
|
||||
await ConnectToMqttAsync();
|
||||
}
|
||||
|
||||
public void SetPhase(string phaseName)
|
||||
{
|
||||
string fileName = $"{phaseName}_Data_{DateTime.Now:yyyyMMdd_HHmmss}.csv";
|
||||
_currentCsvFilePath = Path.Combine(_subjectFolderPath, phaseName, fileName);
|
||||
|
||||
if (!File.Exists(_currentCsvFilePath))
|
||||
{
|
||||
File.WriteAllText(_currentCsvFilePath, "Timestamp;HR;GSR\n");
|
||||
}
|
||||
|
||||
Debug.Log($"[ExperimentManager] Now logging to: {_currentCsvFilePath}");
|
||||
}
|
||||
|
||||
public string GetCurrentFolderPath()
|
||||
{
|
||||
if (string.IsNullOrEmpty(_currentCsvFilePath)) return null;
|
||||
return Path.GetDirectoryName(_currentCsvFilePath);
|
||||
}
|
||||
|
||||
public void StopLogging()
|
||||
{
|
||||
_currentCsvFilePath = null;
|
||||
Debug.Log("[ExperimentManager] Logging stopped. Data collection finished.");
|
||||
}
|
||||
|
||||
private async Task ConnectToMqttAsync()
|
||||
{
|
||||
var factory = new MqttFactory();
|
||||
_mqttClient = factory.CreateMqttClient();
|
||||
|
||||
var options = new MqttClientOptionsBuilder()
|
||||
.WithTcpServer(brokerIp, port)
|
||||
.Build();
|
||||
|
||||
_mqttClient.ApplicationMessageReceivedAsync += e =>
|
||||
{
|
||||
string payload = Encoding.UTF8.GetString(e.ApplicationMessage.PayloadSegment);
|
||||
try
|
||||
{
|
||||
SensorData data = JsonUtility.FromJson<SensorData>(payload);
|
||||
_dataQueue.Enqueue(data);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogWarning($"[MQTT] Parse error: {ex.Message}");
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
await _mqttClient.ConnectAsync(options, CancellationToken.None);
|
||||
var subOptions = new MqttClientSubscribeOptionsBuilder()
|
||||
.WithTopicFilter(topic)
|
||||
.Build();
|
||||
|
||||
await _mqttClient.SubscribeAsync(subOptions, CancellationToken.None);
|
||||
Debug.Log("<color=green>[MQTT] Connected successfully!</color>");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogError($"<color=red>[MQTT] Connection Error: {ex.Message}</color>");
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
bool receivedNewDataThisFrame = false;
|
||||
|
||||
// Opró¿nianie kolejki i zapis
|
||||
while (_dataQueue.TryDequeue(out SensorData newData))
|
||||
{
|
||||
receivedNewDataThisFrame = true;
|
||||
|
||||
if (!string.IsNullOrEmpty(_currentCsvFilePath))
|
||||
{
|
||||
string timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
|
||||
string csvLine = $"{timestamp};{newData.hr};{newData.gsr}\n";
|
||||
File.AppendAllText(_currentCsvFilePath, csvLine);
|
||||
}
|
||||
}
|
||||
|
||||
// --- SYSTEM WATCHDOG (Pilnowanie transmisji) ---
|
||||
if (receivedNewDataThisFrame)
|
||||
{
|
||||
_timeSinceLastMessage = 0f; // Resetujemy stoper
|
||||
|
||||
if (_isDataTimeoutWarningShown)
|
||||
{
|
||||
// Jeœli wczeœniej wywaliliœmy b³¹d, a teraz dane wróci³y, dajemy znaæ, ¿e ju¿ jest OK
|
||||
Debug.Log("<color=green>[ExperimentManager] Transmisja odzyskana! M5Stick znów nadaje.</color>");
|
||||
_isDataTimeoutWarningShown = false;
|
||||
}
|
||||
}
|
||||
else if (_mqttClient != null && _mqttClient.IsConnected)
|
||||
{
|
||||
// Czas leci tylko wtedy, gdy Unity myœli, ¿e MQTT jest po³¹czone
|
||||
_timeSinceLastMessage += Time.deltaTime;
|
||||
|
||||
if (_timeSinceLastMessage >= timeoutSeconds && !_isDataTimeoutWarningShown)
|
||||
{
|
||||
Debug.LogError($"<color=red><b>[UWAGA MQTT!]</b> Brak danych od {timeoutSeconds} sekund! SprawdŸ M5Stick!</color>");
|
||||
_isDataTimeoutWarningShown = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async void OnApplicationQuit()
|
||||
{
|
||||
if (_mqttClient != null && _mqttClient.IsConnected)
|
||||
{
|
||||
await _mqttClient.DisconnectAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/ExperimentManager.cs.meta
Normal file
2
Assets/Scripts/ExperimentManager.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 52698dc1670b8a64b9650b7aab0bba37
|
||||
8
Assets/Scripts/ExperimentalSceneScripts.meta
Normal file
8
Assets/Scripts/ExperimentalSceneScripts.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 132edaef876de554fa42022095a550f0
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
28
Assets/Scripts/ExperimentalSceneScripts/FinalFlagTrigger.cs
Normal file
28
Assets/Scripts/ExperimentalSceneScripts/FinalFlagTrigger.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class FinalFlagTrigger : MonoBehaviour
|
||||
{
|
||||
[Header("End Scene Settings")]
|
||||
public string thankYouSceneName = "ThankYouScene"; // Nazwa sceny z podziêkowaniami
|
||||
|
||||
private bool _hasTriggered = false;
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (other.CompareTag("Player") && !_hasTriggered)
|
||||
{
|
||||
_hasTriggered = true;
|
||||
Debug.Log("[FinalFlagTrigger] Gracz dotar³ do koñca! Zatrzymujê badanie.");
|
||||
|
||||
// 1. Zatrzymujemy zapis do plików CSV w Mened¿erze
|
||||
if (ExperimentManager.Instance != null)
|
||||
{
|
||||
ExperimentManager.Instance.StopLogging();
|
||||
}
|
||||
|
||||
// 2. £adujemy scenê koñcow¹
|
||||
SceneManager.LoadScene(thankYouSceneName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 011468f91b44a8d4ab948e154dbf8634
|
||||
@@ -1,59 +0,0 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.InputSystem.Utilities;
|
||||
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
[Header("Interfejs")]
|
||||
public GameObject startUI; // Twój Canvas z napisem
|
||||
|
||||
[Header("Skrypty Gracza")]
|
||||
public PlayerMove playerMove; // Skrypt poruszania fasolk¹
|
||||
public MouseLook mouseLook; // Skrypt obracania kamer¹
|
||||
|
||||
[Header("Modu³ MQTT")]
|
||||
public MqttCollector mqttCollector; // Skrypt MQTTnet
|
||||
|
||||
private bool hasStarted = false;
|
||||
|
||||
void Start()
|
||||
{
|
||||
// 1. Upewnij siê, ¿e na starcie wszystko jest zablokowane
|
||||
if (playerMove != null) playerMove.enabled = false;
|
||||
if (mouseLook != null) mouseLook.canLook = false;
|
||||
|
||||
// 2. Kursor musi byæ widoczny i wolny, ¿eby gracz wiedzia³, ¿e gra jeszcze nie ruszy³a
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
Cursor.visible = true;
|
||||
|
||||
// 3. Czekamy na "Any Key" (dowolny przycisk klawiatury, myszy lub kontrolera VR)
|
||||
InputSystem.onAnyButtonPress.CallOnce(ctrl => StartGame());
|
||||
|
||||
Debug.Log("GameManager: Oczekiwanie na start...");
|
||||
}
|
||||
|
||||
void StartGame()
|
||||
{
|
||||
if (hasStarted) return;
|
||||
hasStarted = true;
|
||||
|
||||
// 1. Ukrywamy UI
|
||||
if (startUI != null)
|
||||
startUI.SetActive(false);
|
||||
|
||||
// 2. Odblokowujemy ruch i kamerê
|
||||
if (playerMove != null)
|
||||
playerMove.enabled = true;
|
||||
|
||||
if (mouseLook != null)
|
||||
mouseLook.EnableLooking(); // Ta funkcja schowa te¿ kursor
|
||||
|
||||
// 3. Odpalamy zbieranie danych MQTT
|
||||
if (mqttCollector != null)
|
||||
{
|
||||
mqttCollector.BeginSession();
|
||||
}
|
||||
|
||||
Debug.Log("<color=green>SYSTEM: Gra i logowanie danych uruchomione!</color>");
|
||||
}
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9814a729a72ea7245aee98f3c0831d15
|
||||
@@ -1,8 +0,0 @@
|
||||
using System;
|
||||
|
||||
[Serializable]
|
||||
public class HeartRateData
|
||||
{
|
||||
// Jeśli serwer wysyła {"hr": 70}, to musi być 'hr'
|
||||
public int hr;
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1c96e46d44abafb408a15a62a85febe7
|
||||
8
Assets/Scripts/InitialSceneScripts.meta
Normal file
8
Assets/Scripts/InitialSceneScripts.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fd2c9d86103e7d34981792454a51f494
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
30
Assets/Scripts/InitialSceneScripts/MenuController.cs
Normal file
30
Assets/Scripts/InitialSceneScripts/MenuController.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class MenuController : MonoBehaviour
|
||||
{
|
||||
[Header("UI References")]
|
||||
public TMP_InputField subjectIdInput;
|
||||
|
||||
[Header("Scene Settings")]
|
||||
public string firstSceneName = "InstructionScene";
|
||||
|
||||
public void OnStartButtonClicked()
|
||||
{
|
||||
string subjectId = subjectIdInput.text.Trim();
|
||||
|
||||
// Fallback in case you forget to type an ID
|
||||
if (string.IsNullOrEmpty(subjectId))
|
||||
{
|
||||
subjectId = "Test_Subject_01";
|
||||
Debug.LogWarning("[MenuController] ID was empty. Using default ID.");
|
||||
}
|
||||
|
||||
// 1. Create folders and connect to MQTT
|
||||
ExperimentManager.Instance.InitializeSession(subjectId);
|
||||
|
||||
// 2. Load the next scene
|
||||
SceneManager.LoadScene(firstSceneName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9912f425acc8c9848a58758a3da17026
|
||||
8
Assets/Scripts/InstructionScripts.meta
Normal file
8
Assets/Scripts/InstructionScripts.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 862c14a28bb45f94b9ec0e78dbd01380
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
24
Assets/Scripts/InstructionScripts/InstructionController.cs
Normal file
24
Assets/Scripts/InstructionScripts/InstructionController.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class InstructionController : MonoBehaviour
|
||||
{
|
||||
[Header("Scene Settings")]
|
||||
public string nextSceneName = "NeutralScene";
|
||||
|
||||
public void StartNeutralPhase()
|
||||
{
|
||||
Debug.Log("[InstructionController] Button clicked. Starting Neutral phase.");
|
||||
|
||||
if (ExperimentManager.Instance != null)
|
||||
{
|
||||
ExperimentManager.Instance.SetPhase("Neutral");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("[InstructionController] ExperimentManager not found! Start from InitialScene.");
|
||||
}
|
||||
|
||||
SceneManager.LoadScene(nextSceneName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 795ee5d5d52d30d448ecaca241e2f893
|
||||
@@ -1,89 +0,0 @@
|
||||
using UnityEngine;
|
||||
using MQTTnet;
|
||||
using MQTTnet.Client;
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
public class MqttCollector : MonoBehaviour
|
||||
{
|
||||
private IMqttClient _mqttClient;
|
||||
private string _csvPath;
|
||||
|
||||
[Header("Ustawienia MQTT")]
|
||||
public string brokerIp = "127.0.0.1";
|
||||
public int port = 1883;
|
||||
public string topic = "sensor/heartrate";
|
||||
|
||||
// Funkcja wywo³ywana przez GameManager
|
||||
public async void BeginSession()
|
||||
{
|
||||
// 1. Stworzenie pliku CSV w folderze projektu
|
||||
string folder = Application.persistentDataPath + "/Sesje_Badawcze/";
|
||||
if (!Directory.Exists(folder)) Directory.CreateDirectory(folder);
|
||||
|
||||
_csvPath = folder + "Dane_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".csv";
|
||||
File.WriteAllText(_csvPath, "Timestamp;Godzina;Tetno\n");
|
||||
|
||||
Debug.Log($"<color=cyan>MQTT: Plik zapisu: {_csvPath}</color>");
|
||||
|
||||
// 2. Konfiguracja MQTTnet
|
||||
var factory = new MqttFactory();
|
||||
_mqttClient = factory.CreateMqttClient();
|
||||
|
||||
var options = new MqttClientOptionsBuilder()
|
||||
.WithTcpServer(brokerIp, port)
|
||||
.Build();
|
||||
|
||||
// 3. Reakcja na odebran¹ wiadomoœæ
|
||||
_mqttClient.ApplicationMessageReceivedAsync += e =>
|
||||
{
|
||||
string payload = Encoding.UTF8.GetString(e.ApplicationMessage.PayloadSegment);
|
||||
SaveData(payload);
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
|
||||
// 4. Po³¹czenie asynchroniczne
|
||||
try
|
||||
{
|
||||
await _mqttClient.ConnectAsync(options, CancellationToken.None);
|
||||
|
||||
var subOptions = new MqttClientSubscribeOptionsBuilder()
|
||||
.WithTopicFilter(topic)
|
||||
.Build();
|
||||
|
||||
await _mqttClient.SubscribeAsync(subOptions, CancellationToken.None);
|
||||
Debug.Log("<color=green>MQTT: Po³¹czono i s³ucham têtna!</color>");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogError($"MQTT Connection Error: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveData(string json)
|
||||
{
|
||||
try
|
||||
{
|
||||
HeartRateData data = JsonUtility.FromJson<HeartRateData>(json);
|
||||
|
||||
// Format: Data i czas ; têtno
|
||||
string timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
string line = $"{timestamp};{data.hr}\n";
|
||||
|
||||
File.AppendAllText(_csvPath, line);
|
||||
Debug.Log($"<color=white>Zapisano HR: {data.hr}</color>");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogWarning($"B³¹d parsowania: {json}. Szczegó³y: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private async void OnApplicationQuit()
|
||||
{
|
||||
if (_mqttClient != null) await _mqttClient.DisconnectAsync();
|
||||
}
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d97d018fed6c13e4d825d7e154421c63
|
||||
8
Assets/Scripts/NeutralSceneScripts.meta
Normal file
8
Assets/Scripts/NeutralSceneScripts.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 93928c0664501694895c26bc8f4456c8
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
36
Assets/Scripts/NeutralSceneScripts/FlagTrigger.cs
Normal file
36
Assets/Scripts/NeutralSceneScripts/FlagTrigger.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class FlagTrigger : MonoBehaviour
|
||||
{
|
||||
[Header("Ustawienia Przejœcia")]
|
||||
public string nextSceneName = "ExperimentalScene"; // Nazwa sceny badawczej
|
||||
public string nextPhaseName = "Experimental"; // Nazwa folderu/fazy dla mened¿era
|
||||
|
||||
// Zabezpieczenie, ¿eby scena nie próbowa³a siê za³adowaæ 5 razy w u³amku sekundy
|
||||
private bool _hasTriggered = false;
|
||||
|
||||
// Ta funkcja wywo³uje siê automatycznie, gdy inny obiekt z Colliderem wejdzie w ten obiekt
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
// Sprawdzamy, czy obiekt, który nas dotkn¹³, ma tag "Player"
|
||||
if (other.CompareTag("Player") && !_hasTriggered)
|
||||
{
|
||||
_hasTriggered = true;
|
||||
Debug.Log("[FlagTrigger] Gracz dotkn¹³ flagi! Zmieniam fazê i scenê.");
|
||||
|
||||
// 1. Zmieniamy fazê w Mened¿erze (tworzy siê nowy plik CSV)
|
||||
if (ExperimentManager.Instance != null)
|
||||
{
|
||||
ExperimentManager.Instance.SetPhase(nextPhaseName);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("[FlagTrigger] Nie znaleziono ExperimentManager!");
|
||||
}
|
||||
|
||||
// 2. £adujemy now¹ scenê
|
||||
SceneManager.LoadScene(nextSceneName);
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/NeutralSceneScripts/FlagTrigger.cs.meta
Normal file
2
Assets/Scripts/NeutralSceneScripts/FlagTrigger.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b3bfbc8bc04b85040857d42b2375b3e1
|
||||
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);
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/PlayerTracker.cs.meta
Normal file
2
Assets/Scripts/PlayerTracker.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 780a16b5f80ffe5488881d1696a000fc
|
||||
8
Assets/Scripts/TestingMovement.meta
Normal file
8
Assets/Scripts/TestingMovement.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6db6feb39d93b88419c9c666a7c683cb
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -31,7 +31,7 @@ public class MouseLook : MonoBehaviour
|
||||
// Jeśli to zobaczysz w konsoli, znaczy że system działa, a problem jest w skali
|
||||
if (mouseDelta != Vector2.zero)
|
||||
{
|
||||
Debug.Log($"Ruch myszy: {mouseDelta}");
|
||||
//Debug.Log($"Ruch myszy: {mouseDelta}");
|
||||
}
|
||||
|
||||
float mouseX = mouseDelta.x * mouseSensitivity * 0.1f; // Zmniejszyłem mnożnik dla testu
|
||||
Reference in New Issue
Block a user