Person.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using Assets.StreetLight.Scripts;
  2. using System;
  3. using System.ComponentModel;
  4. using System.Runtime.CompilerServices;
  5. using UnityEngine;
  6. namespace Assets.StreetLight.Poco
  7. {
  8. public class Person : INotifyPropertyChanged
  9. {
  10. public int Id { get; }
  11. public event PropertyChangedEventHandler PropertyChanged;
  12. private Vector3 worldPosition = Vector3.zero;
  13. private readonly PositionCalculator positionCalculator;
  14. public Vector3 WorldPosition
  15. {
  16. get => worldPosition;
  17. set => OnPropertyChanged(ref worldPosition, value);
  18. }
  19. public Person(int id, PositionCalculator positionCalculator)
  20. {
  21. Id = id;
  22. this.positionCalculator = positionCalculator;
  23. }
  24. public Vector3 GetUnityPosition()
  25. {
  26. if (positionCalculator == null)
  27. {
  28. throw new InvalidOperationException("Cannot calculate Unity position because the PositionCalculator is not initialized. This might occur when the homography file is not found or not in the right format.");
  29. }
  30. return positionCalculator.WorldPositionToUnityPosition(WorldPosition);
  31. }
  32. private void OnPropertyChanged<T>(ref T field, T value, [CallerMemberName] string propertyName = null)
  33. {
  34. if (!field.Equals(value))
  35. {
  36. field = value;
  37. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  38. }
  39. }
  40. }
  41. }