MockLocationProvider.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using UnityEngine;
  2. namespace ARLocation
  3. {
  4. public class MockLocationProvider : AbstractLocationProvider
  5. {
  6. public override string Name => "MockLocationProvider";
  7. public override bool IsCompassEnabled => true;
  8. public Location mockLocation = new Location();
  9. private bool requested = true;
  10. private bool first = true;
  11. protected override HeadingReading? ReadHeading()
  12. {
  13. var mainCamera = Camera.main;
  14. if (mainCamera != null)
  15. {
  16. var transform = mainCamera.transform;
  17. var localEulerAngles = transform.localEulerAngles;
  18. return new HeadingReading
  19. {
  20. heading = localEulerAngles.y,
  21. magneticHeading = localEulerAngles.y,
  22. accuracy = 0,
  23. isMagneticHeadingAvailable = true,
  24. timestamp = (long)(Time.time * 1000)
  25. };
  26. }
  27. else
  28. {
  29. return new HeadingReading
  30. {
  31. heading = 0,
  32. magneticHeading = 0,
  33. accuracy = 0,
  34. isMagneticHeadingAvailable = true,
  35. timestamp = (long)(Time.time * 1000)
  36. };
  37. }
  38. }
  39. protected override LocationReading? ReadLocation()
  40. {
  41. if (first)
  42. {
  43. first = false;
  44. return new LocationReading
  45. {
  46. latitude = mockLocation.Latitude,
  47. longitude = mockLocation.Longitude,
  48. altitude = mockLocation.Altitude,
  49. accuracy = 0.0,
  50. floor = -1,
  51. timestamp = (long)(Time.time * 1000)
  52. };
  53. }
  54. return null;
  55. }
  56. protected override void RequestLocationAndCompassUpdates()
  57. {
  58. requested = true;
  59. }
  60. protected override void UpdateLocationRequestStatus()
  61. {
  62. if (requested)
  63. {
  64. Status = LocationProviderStatus.Initializing;
  65. requested = false;
  66. }
  67. if (Status == LocationProviderStatus.Initializing)
  68. {
  69. Status = LocationProviderStatus.Started;
  70. }
  71. }
  72. }
  73. }