123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- using Assets.StreetLight.Scripts;
- 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;
- namespace Assets
- {
- public class CalibrationRecorderBehavior : MonoBehaviour
- {
- PersonManager PersonManager => personManagerLazy.Value;
- Lazy<PersonManager> personManagerLazy;
- private void Awake()
- {
- personManagerLazy = new Lazy<PersonManager>(FindObjectOfType<PersonManager>);
- }
- BlockingCollection<Action> taskQueue;
- string fileName = @$"C:\Users\nick.steyer\Desktop\{DateTime.Now:yyyy-dd-M_HH-mm-ss}.csv";
- void Start()
- {
- taskQueue = new BlockingCollection<Action>();
- 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());
- }
- }
- }
- }
|