LocationProviderInfo.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. namespace ARLocation.UI
  6. {
  7. public class LocationProviderInfo : MonoBehaviour
  8. {
  9. private List<Text> texts = new List<Text>();
  10. private ARLocationProvider locationProvider;
  11. private LoadingBar accuracyBar;
  12. private Transform mainCameraTransform;
  13. // Use this for initialization
  14. void Start()
  15. {
  16. texts.Add(GameObject.Find(gameObject.name + "/Panel/Canvas/Provider").GetComponent<Text>());
  17. texts.Add(GameObject.Find(gameObject.name + "/Panel/Canvas/Latitude").GetComponent<Text>());
  18. texts.Add(GameObject.Find(gameObject.name + "/Panel/Canvas/Longitude").GetComponent<Text>());
  19. texts.Add(GameObject.Find(gameObject.name + "/Panel/Canvas/Altitude").GetComponent<Text>());
  20. texts.Add(GameObject.Find(gameObject.name + "/Panel/Canvas/Time").GetComponent<Text>());
  21. texts.Add(GameObject.Find(gameObject.name + "/Panel/Canvas/Status").GetComponent<Text>());
  22. texts.Add(GameObject.Find(gameObject.name + "/Panel/Canvas Right/DistanceWalked").GetComponent<Text>());
  23. texts.Add(GameObject.Find(gameObject.name + "/Panel/Canvas Right/CameraPosition").GetComponent<Text>());
  24. texts.Add(GameObject.Find(gameObject.name + "/Panel/Canvas Right/MagneticSensor").GetComponent<Text>());
  25. locationProvider = ARLocationProvider.Instance;
  26. accuracyBar = GameObject.Find(gameObject.name + "/Panel/Canvas/LoadingBar").GetComponent<LoadingBar>();
  27. mainCameraTransform = ARLocationManager.Instance.MainCamera.transform;
  28. }
  29. // Update is called once per frame
  30. void Update()
  31. {
  32. texts[0].text = "Provider: " + locationProvider.Provider.Name;
  33. texts[1].text = "Latitude: " + locationProvider.CurrentLocation.latitude;
  34. texts[2].text = "Longitude: " + locationProvider.CurrentLocation.longitude;
  35. texts[3].text = "Altitude: " + locationProvider.CurrentLocation.altitude;
  36. DateTime epochStart = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
  37. long currentEpochTime = (long)((DateTime.UtcNow - epochStart).TotalSeconds * 1000.0);
  38. texts[4].text = "Time Since Last (ms): " + (currentEpochTime - locationProvider.CurrentLocation.timestamp);
  39. texts[5].text = "Status: " + locationProvider.Provider.GetStatusString();
  40. texts[6].text = "Distance Walked: " + locationProvider.Provider.DistanceFromStartPoint;
  41. texts[7].text = "Camera Pos: " + mainCameraTransform.position;
  42. texts[8].text = "MagneticSensor: " + locationProvider.Provider.IsCompassEnabled;
  43. var accuracy = locationProvider.CurrentLocation.accuracy;
  44. accuracyBar.FillPercentage = Mathf.Min(1, (float)accuracy / 25.0f);
  45. accuracyBar.Text = "" + (float)locationProvider.CurrentLocation.accuracy;
  46. }
  47. }
  48. }