ProfilerMonoBlock.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System;
  2. using SRF;
  3. using UnityEngine;
  4. using UnityEngine.Profiling;
  5. using UnityEngine.UI;
  6. namespace SRDebugger.UI.Controls
  7. {
  8. public class ProfilerMonoBlock : SRMonoBehaviourEx
  9. {
  10. protected override void OnEnable()
  11. {
  12. base.OnEnable();
  13. this._isSupported = (UnityEngine.Profiling.Profiler.GetMonoUsedSizeLong() > 0L);
  14. this.NotSupportedMessage.SetActive(!this._isSupported);
  15. this.CurrentUsedText.gameObject.SetActive(this._isSupported);
  16. this.TriggerRefresh();
  17. }
  18. protected override void Update()
  19. {
  20. base.Update();
  21. if (SRDebug.Instance.IsDebugPanelVisible && Time.realtimeSinceStartup - this._lastRefresh > 1f)
  22. {
  23. this.TriggerRefresh();
  24. this._lastRefresh = Time.realtimeSinceStartup;
  25. }
  26. }
  27. public void TriggerRefresh()
  28. {
  29. long num = (!this._isSupported) ? GC.GetTotalMemory(false) : UnityEngine.Profiling.Profiler.GetMonoHeapSizeLong();
  30. long monoUsedSizeLong = UnityEngine.Profiling.Profiler.GetMonoUsedSizeLong();
  31. long num2 = num >> 10;
  32. num2 /= 1024L;
  33. long num3 = monoUsedSizeLong >> 10;
  34. num3 /= 1024L;
  35. this.Slider.maxValue = (float)num2;
  36. this.Slider.value = (float)num3;
  37. this.TotalAllocatedText.text = "Total: <color=#FFFFFF>{0}</color>MB".Fmt(new object[]
  38. {
  39. num2
  40. });
  41. if (num3 > 0L)
  42. {
  43. this.CurrentUsedText.text = "<color=#FFFFFF>{0}</color>MB".Fmt(new object[]
  44. {
  45. num3
  46. });
  47. }
  48. }
  49. public void TriggerCollection()
  50. {
  51. GC.Collect();
  52. this.TriggerRefresh();
  53. }
  54. private float _lastRefresh;
  55. [RequiredField]
  56. public Text CurrentUsedText;
  57. [RequiredField]
  58. public GameObject NotSupportedMessage;
  59. [RequiredField]
  60. public Slider Slider;
  61. [RequiredField]
  62. public Text TotalAllocatedText;
  63. private bool _isSupported;
  64. }
  65. }