DebuggerComponent.ScrollableDebuggerWindowBase.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //------------------------------------------------------------
  2. // Game Framework
  3. // Copyright © 2013-2021 loyalsoft. All rights reserved.
  4. // Homepage: http://www.game7000.com/
  5. // Feedback: http://www.game7000.com/
  6. //------------------------------------------------------------
  7. using GameFramework;
  8. using GameFramework.Debugger;
  9. using UnityEngine;
  10. namespace UnityGameFramework.Runtime
  11. {
  12. public sealed partial class DebuggerComponent : GameFrameworkComponent
  13. {
  14. private abstract class ScrollableDebuggerWindowBase : IDebuggerWindow
  15. {
  16. private const float TitleWidth = 240f;
  17. private Vector2 m_ScrollPosition = Vector2.zero;
  18. public virtual void Initialize(params object[] args)
  19. {
  20. }
  21. public virtual void Shutdown()
  22. {
  23. }
  24. public virtual void OnEnter()
  25. {
  26. }
  27. public virtual void OnLeave()
  28. {
  29. }
  30. public virtual void OnUpdate(float elapseSeconds, float realElapseSeconds)
  31. {
  32. }
  33. public void OnDraw()
  34. {
  35. m_ScrollPosition = GUILayout.BeginScrollView(m_ScrollPosition);
  36. {
  37. OnDrawScrollableWindow();
  38. }
  39. GUILayout.EndScrollView();
  40. }
  41. protected abstract void OnDrawScrollableWindow();
  42. protected static void DrawItem(string title, string content)
  43. {
  44. GUILayout.BeginHorizontal();
  45. {
  46. GUILayout.Label(title, GUILayout.Width(TitleWidth));
  47. if (GUILayout.Button(content, "label"))
  48. {
  49. CopyToClipboard(content);
  50. }
  51. }
  52. GUILayout.EndHorizontal();
  53. }
  54. protected static string GetByteLengthString(long byteLength)
  55. {
  56. if (byteLength < 1024L) // 2 ^ 10
  57. {
  58. return Utility.Text.Format("{0} Bytes", byteLength.ToString());
  59. }
  60. if (byteLength < 1048576L) // 2 ^ 20
  61. {
  62. return Utility.Text.Format("{0} KB", (byteLength / 1024f).ToString("F2"));
  63. }
  64. if (byteLength < 1073741824L) // 2 ^ 30
  65. {
  66. return Utility.Text.Format("{0} MB", (byteLength / 1048576f).ToString("F2"));
  67. }
  68. if (byteLength < 1099511627776L) // 2 ^ 40
  69. {
  70. return Utility.Text.Format("{0} GB", (byteLength / 1073741824f).ToString("F2"));
  71. }
  72. if (byteLength < 1125899906842624L) // 2 ^ 50
  73. {
  74. return Utility.Text.Format("{0} TB", (byteLength / 1099511627776f).ToString("F2"));
  75. }
  76. if (byteLength < 1152921504606846976L) // 2 ^ 60
  77. {
  78. return Utility.Text.Format("{0} PB", (byteLength / 1125899906842624f).ToString("F2"));
  79. }
  80. return Utility.Text.Format("{0} EB", (byteLength / 1152921504606846976f).ToString("F2"));
  81. }
  82. }
  83. }
  84. }