ProfilerGraphAxisLabel.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. namespace SRDebugger.UI.Controls
  2. {
  3. using SRF;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. [RequireComponent(typeof (RectTransform))]
  7. public class ProfilerGraphAxisLabel : SRMonoBehaviourEx
  8. {
  9. private float _prevFrameTime;
  10. private float? _queuedFrameTime;
  11. private float _yPosition;
  12. [RequiredField] public Text Text;
  13. protected override void Update()
  14. {
  15. base.Update();
  16. if (_queuedFrameTime.HasValue)
  17. {
  18. SetValueInternal(_queuedFrameTime.Value);
  19. _queuedFrameTime = null;
  20. }
  21. }
  22. public void SetValue(float frameTime, float yPosition)
  23. {
  24. if (_prevFrameTime == frameTime && _yPosition == yPosition)
  25. {
  26. return;
  27. }
  28. _queuedFrameTime = frameTime;
  29. _yPosition = yPosition;
  30. }
  31. private void SetValueInternal(float frameTime)
  32. {
  33. _prevFrameTime = frameTime;
  34. var ms = Mathf.FloorToInt(frameTime*1000);
  35. var fps = Mathf.RoundToInt(1f/frameTime);
  36. Text.text = "{0}ms ({1}FPS)".Fmt(ms, fps);
  37. var r = (RectTransform) CachedTransform;
  38. r.anchoredPosition = new Vector2(r.rect.width*0.5f + 10f, _yPosition);
  39. }
  40. }
  41. }