PersonManager.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using Assets.StreetLight.Adapters;
  2. using Assets.StreetLight.Interfaces;
  3. using Assets.StreetLight.Poco;
  4. using System;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using System.Collections.ObjectModel;
  8. using System.Globalization;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Runtime.CompilerServices;
  12. using System.Text;
  13. using System.Threading;
  14. using UnityEngine;
  15. namespace Assets.StreetLight.Scripts
  16. {
  17. public class PersonManager : MonoBehaviour
  18. {
  19. public ObservableCollection<Person> Persons { get; private set; }
  20. public PositionCalculator PositionCalculator { get; private set; }
  21. private IPersonDetector personDetector;
  22. void Start()
  23. {
  24. var filePath = @"C:\Users\nick.steyer\SmartStreetLight\StreetLight\Calibration.csv";
  25. var calibrationPoints = new List<CalibrationPoint>();
  26. var lines = File.ReadAllLines(filePath);
  27. foreach (var line in lines.Skip(1))
  28. {
  29. var coordinates = line.Split(',').Skip(1).ToArray();
  30. calibrationPoints.Add(new CalibrationPoint(
  31. new Vector3(
  32. float.Parse(coordinates[0], CultureInfo.InvariantCulture),
  33. float.Parse(coordinates[1], CultureInfo.InvariantCulture),
  34. float.Parse(coordinates[2], CultureInfo.InvariantCulture)),
  35. new Vector3(
  36. float.Parse(coordinates[3], CultureInfo.InvariantCulture),
  37. float.Parse(coordinates[4], CultureInfo.InvariantCulture),
  38. float.Parse(coordinates[5], CultureInfo.InvariantCulture))));
  39. }
  40. PositionCalculator = new PositionCalculator(calibrationPoints);
  41. Persons = new ObservableCollection<Person>();
  42. personDetector = new ZedPersonDetector(FindObjectOfType<ZEDManager>());
  43. personDetector.PersonsDetected += PersonDetector_PersonsDetected;
  44. }
  45. private void PersonDetector_PersonsDetected(object sender, IEnumerable<Person> e)
  46. {
  47. Persons.Clear();
  48. foreach (var person in e)
  49. {
  50. Persons.Add(person);
  51. }
  52. }
  53. void Update()
  54. {
  55. }
  56. }
  57. }