ProfilerGraphAxisLabel.cs 1.3 KB

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