HoloLensStatusDisplay.cs 1000 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using UnityEngine;
  2. public class HoloLensStatusDisplay:MonoBehaviour {
  3. private int _frames = 0;
  4. private float _updateInterval = 0.10f; // Time to wait, in seconds
  5. private float _lastUpdate = 0;
  6. private TextMesh _textMesh;
  7. private GazeWatcher _gazeWatcher;
  8. void Start() {
  9. _textMesh = GetComponent<TextMesh>();
  10. _gazeWatcher = new GazeWatcher(Camera.main);
  11. }
  12. void Update() {
  13. _frames++;
  14. if (Time.time - _lastUpdate > _updateInterval) {
  15. updateValues();
  16. }
  17. }
  18. void updateValues() {
  19. float timePassed = Time.time - _lastUpdate;
  20. float msec = timePassed / (float)_frames * 1000f;
  21. float fps = _frames / timePassed;
  22. _lastUpdate += timePassed;
  23. _frames = 0;
  24. var caption = "";
  25. caption += string.Format("Time: {0:0.0}ms", msec);
  26. caption += "\n";
  27. caption += string.Format("FPS: {0:0.} ", fps);
  28. caption += "\n";
  29. caption += "Camera rot: " + _gazeWatcher.direction;
  30. caption += "\n";
  31. caption += "Camera pos: " + _gazeWatcher.position;
  32. _textMesh.text = caption;
  33. }
  34. }