1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- using Assets.StreetLight.Adapters;
- using Assets.StreetLight.Interfaces;
- using Assets.StreetLight.Poco;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Globalization;
- using System.IO;
- using System.Linq;
- using UnityEngine;
- namespace Assets.StreetLight.Scripts
- {
- public class PersonManager : MonoBehaviour
- {
- public ObservableCollection<Person> Persons { get; private set; }
- public PositionCalculator PositionCalculator { get; private set; }
- private IPersonDetector personDetector;
- public event EventHandler DetectionReady;
- void Start()
- {
- var lines = File.ReadAllLines(Configuration.Instance.InputCalibrationFilePath);
- var calibrationPoints = new List<CalibrationPoint>();
- foreach (var line in lines.Skip(1))
- {
- var coordinates = line.Split(',').Skip(1).ToArray();
- calibrationPoints.Add(new CalibrationPoint(
- new Vector3(
- float.Parse(coordinates[0], CultureInfo.InvariantCulture),
- float.Parse(coordinates[1], CultureInfo.InvariantCulture),
- float.Parse(coordinates[2], CultureInfo.InvariantCulture)),
- new Vector3(
- float.Parse(coordinates[3], CultureInfo.InvariantCulture),
- float.Parse(coordinates[4], CultureInfo.InvariantCulture),
- float.Parse(coordinates[5], CultureInfo.InvariantCulture))));
- }
- PositionCalculator = new PositionCalculator(calibrationPoints);
- Persons = new ObservableCollection<Person>();
- personDetector = new ZedPersonDetector(FindObjectOfType<ZEDManager>());
- personDetector.PersonsDetected += InvokeDetectionReady;
- personDetector.PersonsDetected += PersonDetector_PersonsDetected;
- }
- private void InvokeDetectionReady(object sender, IEnumerable<Person> e)
- {
- DetectionReady?.Invoke(this, EventArgs.Empty);
- personDetector.PersonsDetected -= InvokeDetectionReady;
- }
- private void PersonDetector_PersonsDetected(object sender, IEnumerable<Person> e)
- {
- Persons.Clear();
- foreach (var person in e)
- {
- Persons.Add(person);
- }
- }
- void Update()
- {
- }
- }
- }
|