ConsoleEntryView.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using System;
  2. using SRDebugger.Internal;
  3. using SRDebugger.Services;
  4. using SRF;
  5. using SRF.UI;
  6. using SRF.UI.Layout;
  7. using UnityEngine;
  8. using UnityEngine.UI;
  9. namespace SRDebugger.UI.Controls
  10. {
  11. [RequireComponent(typeof(RectTransform))]
  12. public class ConsoleEntryView : SRMonoBehaviourEx, IVirtualView
  13. {
  14. public void SetDataContext(object data)
  15. {
  16. ConsoleEntry consoleEntry = data as ConsoleEntry;
  17. if (consoleEntry == null)
  18. {
  19. throw new Exception("Data should be a ConsoleEntry");
  20. }
  21. if (consoleEntry.Count > 1)
  22. {
  23. if (!this._hasCount)
  24. {
  25. this.CountContainer.alpha = 1f;
  26. this._hasCount = true;
  27. }
  28. if (consoleEntry.Count != this._count)
  29. {
  30. this.Count.text = SRDebuggerUtil.GetNumberString(consoleEntry.Count, 999, "999+");
  31. this._count = consoleEntry.Count;
  32. }
  33. }
  34. else if (this._hasCount)
  35. {
  36. this.CountContainer.alpha = 0f;
  37. this._hasCount = false;
  38. }
  39. if (consoleEntry == this._prevData)
  40. {
  41. return;
  42. }
  43. this._prevData = consoleEntry;
  44. this.Message.text = consoleEntry.MessagePreview;
  45. this.StackTrace.text = consoleEntry.StackTracePreview;
  46. if (string.IsNullOrEmpty(this.StackTrace.text))
  47. {
  48. this.Message.rectTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Bottom, 2f, this._rectTransform.rect.height - 4f);
  49. }
  50. else
  51. {
  52. this.Message.rectTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Bottom, 12f, this._rectTransform.rect.height - 14f);
  53. }
  54. switch (consoleEntry.LogType)
  55. {
  56. case LogType.Error:
  57. case LogType.Assert:
  58. case LogType.Exception:
  59. this.ImageStyle.StyleKey = "Console_Error_Blob";
  60. break;
  61. case LogType.Warning:
  62. this.ImageStyle.StyleKey = "Console_Warning_Blob";
  63. break;
  64. case LogType.Log:
  65. this.ImageStyle.StyleKey = "Console_Info_Blob";
  66. break;
  67. }
  68. }
  69. protected override void Awake()
  70. {
  71. base.Awake();
  72. this._rectTransform = (base.CachedTransform as RectTransform);
  73. this.CountContainer.alpha = 0f;
  74. this.Message.supportRichText = Settings.Instance.RichTextInConsole;
  75. }
  76. public const string ConsoleBlobInfo = "Console_Info_Blob";
  77. public const string ConsoleBlobWarning = "Console_Warning_Blob";
  78. public const string ConsoleBlobError = "Console_Error_Blob";
  79. private int _count;
  80. private bool _hasCount;
  81. private ConsoleEntry _prevData;
  82. private RectTransform _rectTransform;
  83. [RequiredField]
  84. public Text Count;
  85. [RequiredField]
  86. public CanvasGroup CountContainer;
  87. [RequiredField]
  88. public StyleComponent ImageStyle;
  89. [RequiredField]
  90. public Text Message;
  91. [RequiredField]
  92. public Text StackTrace;
  93. }
  94. }