SteamVR_Stats.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using UnityEngine;
  4. using Valve.VR;
  5. public class SteamVR_Stats : MonoBehaviour
  6. {
  7. private void Awake()
  8. {
  9. if (this.text == null)
  10. {
  11. this.text = base.GetComponent<GUIText>();
  12. this.text.enabled = false;
  13. }
  14. if (this.fadeDuration > 0f)
  15. {
  16. SteamVR_Fade.Start(this.fadeColor, 0f, false);
  17. SteamVR_Fade.Start(Color.clear, this.fadeDuration, false);
  18. }
  19. }
  20. private void Update()
  21. {
  22. if (this.text != null)
  23. {
  24. if (Input.GetKeyDown(KeyCode.I))
  25. {
  26. this.text.enabled = !this.text.enabled;
  27. }
  28. if (this.text.enabled)
  29. {
  30. CVRCompositor compositor = OpenVR.Compositor;
  31. if (compositor != null)
  32. {
  33. Compositor_FrameTiming compositor_FrameTiming = default(Compositor_FrameTiming);
  34. compositor_FrameTiming.m_nSize = (uint)Marshal.SizeOf(typeof(Compositor_FrameTiming));
  35. compositor.GetFrameTiming(ref compositor_FrameTiming, 0u);
  36. double flSystemTimeInSeconds = compositor_FrameTiming.m_flSystemTimeInSeconds;
  37. if (flSystemTimeInSeconds > this.lastUpdate)
  38. {
  39. double num = (this.lastUpdate <= 0.0) ? 0.0 : (1.0 / (flSystemTimeInSeconds - this.lastUpdate));
  40. this.lastUpdate = flSystemTimeInSeconds;
  41. this.text.text = string.Format("framerate: {0:N0}\ndropped frames: {1}", num, (int)compositor_FrameTiming.m_nNumDroppedFrames);
  42. }
  43. else
  44. {
  45. this.lastUpdate = flSystemTimeInSeconds;
  46. }
  47. }
  48. }
  49. }
  50. }
  51. public GUIText text;
  52. public Color fadeColor = Color.black;
  53. public float fadeDuration = 1f;
  54. private double lastUpdate;
  55. }