CompassAltimeterUpdater.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using Google.Maps.Examples.Shared;
  2. using UnityEngine;
  3. /// <summary>
  4. /// A controller that updates some onscreen HUD elements based on the status of a
  5. /// SimpleViewController on a camera rig.
  6. /// </summary>
  7. public class CompassAltimeterUpdater : MonoBehaviour {
  8. /// <summary>
  9. /// The <see cref="SimpleViewController"/> from which to get altitude and Azimuth.
  10. /// </summary>
  11. [Tooltip("The controller from which to get altitude and Azimuth.")]
  12. public SimpleViewController SimpleViewController;
  13. /// <summary>
  14. /// <see cref="Compass"/> object to update based on Azimuth.
  15. /// </summary>
  16. [Tooltip("Compass object to update based on Azimuth.")]
  17. public GameObject Compass;
  18. /// <summary>
  19. /// <see cref="Altimeter"/> object to update based on transform.y of the SimpleViewController.
  20. /// </summary>
  21. [Tooltip("Altimeter object to update based on transform.y of the SimpleViewController.")]
  22. public GameObject Altimeter;
  23. /// <summary>
  24. /// Movement scale used when updating Altimeter object.
  25. /// </summary>
  26. /// <remarks>
  27. /// This value is configured based on the unity world scale size of the altimeter object. The
  28. /// current altitude (position.y of <see cref="SimpleViewController"/>) is multiplied by this
  29. /// scale factor to get the calibrated vertical movement of the altitude strip.
  30. /// </remarks>
  31. [Tooltip("Movement scale used when updating Altimeter object.")]
  32. public float AltimeterScale = 4.0f;
  33. void Update() {
  34. // Rotate the compass to align with Azimuth.
  35. if (Compass != null) {
  36. Compass.transform.localRotation =
  37. Quaternion.Euler(0, 0, SimpleViewController.Azimuth - 180);
  38. }
  39. // Move Altimeter based on y position of SimpleViewController and AltimeterScale.
  40. if (Altimeter != null) {
  41. float altHeight = -SimpleViewController.transform.position.y * AltimeterScale;
  42. Altimeter.transform.localPosition = new Vector3(0, altHeight, 0);
  43. }
  44. }
  45. }