Slow app when exporting CombinedGaze data into a Json file using Unity
Hello everyone,
I am trying to export the CombinedGaze data to a json file. I made this script, and it works. The problem is that the application turns to run super slow, and I don't know why. Any ideas?
using System.Collections.Generic;
using UnityEngine;
using HP.Omnicept.Unity;
using HP.Omnicept.Messaging.Messages;
using System.IO;
public class WriteGazeData : MonoBehaviour
{
[System.Serializable]
private struct MyAppGD
{
public List<Vector3> rateValues;
}
public float timer;
public bool dataExported;
public string filename = "GazeData_FirstExperiment.json";
private MyAppGD myAppGD;
private GliaBehaviour _gliaBehaviour;
private GliaBehaviour m_gliaBehaviour
{
get
{
if (_gliaBehaviour == null)
{
_gliaBehaviour = FindObjectOfType<GliaBehaviour>();
}
return _gliaBehaviour;
}
}
private string savePath
{
get
{
return $"{Application.streamingAssetsPath}/{filename}";
}
}
#region Unity LifeCycle
private void OnEnable()
{
m_gliaBehaviour.OnEyeTracking.AddListener(HandleGD);
}
private void OnDisable()
{
m_gliaBehaviour.OnEyeTracking.RemoveListener(HandleGD);
}
private void Start()
{
myAppGD = new MyAppGD { rateValues = new List<Vector3>() };
dataExported = false;
}
private void Update()
{
timer -= Time.deltaTime;
if (timer < 0 && dataExported == false)
{
Debug.Log("Data was exported");
SaveToJson();
dataExported = true;
}
}
#endregion
private void HandleGD(EyeTracking gd)
{
if (gd != null)
{
myAppGD.rateValues.Add(new Vector3 (gd.CombinedGaze.X, gd.CombinedGaze.Y, gd.CombinedGaze.Z));
}
}
private void SaveToJson()
{
string json = JsonUtility.ToJson(myAppGD, true);
File.WriteAllText(savePath, json);
Debug.Log($"Saved values at: {savePath}");
}
}
0
Please sign in to leave a comment.
Comments
0 comments