ConsoleTabQuickViewControl.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System;
  2. using SRDebugger.Internal;
  3. using SRDebugger.Services;
  4. using SRF;
  5. using UnityEngine;
  6. using UnityEngine.UI;
  7. namespace SRDebugger.UI.Other
  8. {
  9. public class ConsoleTabQuickViewControl : SRMonoBehaviourEx
  10. {
  11. protected override void Awake()
  12. {
  13. base.Awake();
  14. this.ErrorCountText.text = "0";
  15. this.WarningCountText.text = "0";
  16. this.InfoCountText.text = "0";
  17. }
  18. protected override void Update()
  19. {
  20. base.Update();
  21. if (this.ConsoleService == null)
  22. {
  23. return;
  24. }
  25. if (ConsoleTabQuickViewControl.HasChanged(this.ConsoleService.ErrorCount, ref this._prevErrorCount, 1000))
  26. {
  27. this.ErrorCountText.text = SRDebuggerUtil.GetNumberString(this.ConsoleService.ErrorCount, 1000, ConsoleTabQuickViewControl.MaxString);
  28. }
  29. if (ConsoleTabQuickViewControl.HasChanged(this.ConsoleService.WarningCount, ref this._prevWarningCount, 1000))
  30. {
  31. this.WarningCountText.text = SRDebuggerUtil.GetNumberString(this.ConsoleService.WarningCount, 1000, ConsoleTabQuickViewControl.MaxString);
  32. }
  33. if (ConsoleTabQuickViewControl.HasChanged(this.ConsoleService.InfoCount, ref this._prevInfoCount, 1000))
  34. {
  35. this.InfoCountText.text = SRDebuggerUtil.GetNumberString(this.ConsoleService.InfoCount, 1000, ConsoleTabQuickViewControl.MaxString);
  36. }
  37. }
  38. private static bool HasChanged(int newCount, ref int oldCount, int max)
  39. {
  40. int num = Mathf.Clamp(newCount, 0, max);
  41. int num2 = Mathf.Clamp(oldCount, 0, max);
  42. bool result = num != num2;
  43. oldCount = newCount;
  44. return result;
  45. }
  46. private const int Max = 1000;
  47. private static readonly string MaxString = 999 + "+";
  48. private int _prevErrorCount = -1;
  49. private int _prevInfoCount = -1;
  50. private int _prevWarningCount = -1;
  51. [Import]
  52. public IConsoleService ConsoleService;
  53. [RequiredField]
  54. public Text ErrorCountText;
  55. [RequiredField]
  56. public Text InfoCountText;
  57. [RequiredField]
  58. public Text WarningCountText;
  59. }
  60. }