1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- using System;
- using System.IO;
- using System.Text;
- using UnityEngine;
- public class UIChangeView : MonoBehaviour
- {
- // Inspector variables
- public string logFileName = "";
- // Get from LoggingManager
- private int ParticipantID;
- private string logPathFolder = "";
- // Changes on click
- private int countChanges = 0;
- private bool defaultView = true; // Perspective is default view
- private float timerPerspective = 0f;
- private float timerTopDown = 0f;
- private string logPath;
- private float time = 0f;
- private void Start()
- {
- ParticipantID = gameObject.GetComponentInParent<LoggingManager>().ParticipantID;
- logPathFolder = gameObject.GetComponentInParent<LoggingManager>().LogPathFolder;
- logFileName = "log_" + ParticipantID + "_" + logFileName + ".csv";
- logPath = Path.Combine(logPathFolder, logFileName);
- using (FileStream stream = File.Open(logPath, FileMode.Create))
- {
- using (StreamWriter writer = new StreamWriter(stream))
- {
- writer.WriteLine(GetLogFileHeader());
- writer.Flush();
- }
- }
- Debug.Log("Created new Logfile " + logFileName);
- }
- private string GetLogFileHeader()
- {
- StringBuilder header = new StringBuilder("ParticipantID");
- header.Append(";Time");
- header.Append(";Acc Clicks");
- header.Append(";Acc Time Perspective");
- header.Append(";Acc Time TopDown");
- header.Append(";View");
- return header.ToString();
- }
- public void registerOnButtonClicked()
- {
- countChanges++;
- defaultView = !defaultView;
- }
- private void FixedUpdate()
- {
- if (File.Exists(logPath))
- {
- try
- {
- using (StreamWriter writer = new StreamWriter(logPath, true))
- {
- StringBuilder line = new StringBuilder();
- line.Append(ParticipantID);
- line.Append(";" + time);
- line.Append(";" + countChanges);
- line.Append(";" + timerPerspective);
- line.Append(";" + timerTopDown);
- line.Append(";" + (defaultView ? "Perspective" : "TopDown"));
- writer.WriteLine(line);
- writer.Flush();
- }
- }
- catch (Exception e)
- {
- throw new ApplicationException("Something went wrong by writing into a csv file: ", e);
- }
- }
- time += Time.deltaTime;
- if (defaultView)
- timerPerspective += Time.deltaTime;
- else
- timerTopDown += Time.deltaTime;
- }
- }
|