ConsoleTabQuickViewControl.cs 2.1 KB

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