ProfilerFPSLabel.cs 768 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. using SRDebugger.Services;
  3. using SRF;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. namespace SRDebugger.UI
  7. {
  8. public class ProfilerFPSLabel : SRMonoBehaviourEx
  9. {
  10. protected override void Update()
  11. {
  12. base.Update();
  13. if (Time.realtimeSinceStartup > this._nextUpdate)
  14. {
  15. this.Refresh();
  16. }
  17. }
  18. private void Refresh()
  19. {
  20. this._text.text = "FPS: {0:0.00}".Fmt(new object[]
  21. {
  22. 1f / this._profilerService.AverageFrameTime
  23. });
  24. this._nextUpdate = Time.realtimeSinceStartup + this.UpdateFrequency;
  25. }
  26. private float _nextUpdate;
  27. [Import]
  28. private IProfilerService _profilerService;
  29. public float UpdateFrequency = 1f;
  30. [RequiredField]
  31. [SerializeField]
  32. private Text _text;
  33. }
  34. }