using System; using System.Collections; using System.Collections.Concurrent; using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; using UnityEngine; public class CalibrationRecorderBehavior : MonoBehaviour { PersonManager PersonManager => personManagerLazy.Value; Lazy personManagerLazy; private void Awake() { personManagerLazy = new Lazy(FindObjectOfType); } BlockingCollection taskQueue; string fileName = @$"C:\Users\nick.steyer\Desktop\{DateTime.Now:yyyy-dd-M_HH-mm-ss}.csv"; void Start() { taskQueue = new BlockingCollection(); if (!File.Exists(fileName)) { File.WriteAllLines(fileName, new string[] { "WorldX,WorldY,WorldZ,UnityX,UnityY,UnityZ" }); } } // Update is called once per frame void Update() { var persons = PersonManager.Persons; if (PersonManager.Persons.Count == 1) { var person = PersonManager.Persons.Single(); var marker = GameObject.Find("CalibrationMarker"); var personPosition = person.WorldPosition; var markerPosition = marker.transform.position; taskQueue.Add(() => File.AppendAllLines(fileName, new string[] { FormattableString.Invariant($"{personPosition.x},{personPosition.y},{personPosition.z},{markerPosition.x},{markerPosition.y},{markerPosition.z}") })); Task.Run(() => taskQueue.Take().Invoke()); } } }