SystemInfoHUD.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. using System;
  2. using System.Text;
  3. using UnityEngine;
  4. [ExecuteInEditMode]
  5. public class SystemInfoHUD : MonoBehaviour
  6. {
  7. public void Start()
  8. {
  9. base.useGUILayout = false;
  10. }
  11. public void OnGUI()
  12. {
  13. if (!this.show || (!Application.isPlaying && !this.showInEditor))
  14. {
  15. return;
  16. }
  17. int num = GC.CollectionCount(0);
  18. if (this.lastCollectNum != (float)num)
  19. {
  20. this.lastCollectNum = (float)num;
  21. this.delta = Time.realtimeSinceStartup - this.lastCollect;
  22. this.lastCollect = Time.realtimeSinceStartup;
  23. this.lastDeltaTime = Time.deltaTime;
  24. this.collectAlloc = this.allocMem;
  25. }
  26. this.allocMem = (int)GC.GetTotalMemory(false);
  27. this.peakAlloc = ((this.allocMem <= this.peakAlloc) ? this.peakAlloc : this.allocMem);
  28. if (Time.realtimeSinceStartup - this.lastAllocSet > 0.3f)
  29. {
  30. int num2 = this.allocMem - this.lastAllocMemory;
  31. this.lastAllocMemory = this.allocMem;
  32. this.lastAllocSet = Time.realtimeSinceStartup;
  33. if (num2 >= 0)
  34. {
  35. this.allocRate = num2;
  36. }
  37. }
  38. StringBuilder stringBuilder = new StringBuilder();
  39. stringBuilder.Append("Currently allocated\t");
  40. stringBuilder.Append(((float)this.allocMem / 1000000f).ToString("0"));
  41. stringBuilder.Append("mb\n");
  42. stringBuilder.Append("Peak allocated\t");
  43. stringBuilder.Append(((float)this.peakAlloc / 1000000f).ToString("0"));
  44. stringBuilder.Append("mb (last collect ");
  45. stringBuilder.Append(((float)this.collectAlloc / 1000000f).ToString("0"));
  46. stringBuilder.Append(" mb)\n");
  47. stringBuilder.Append("Allocation rate\t");
  48. stringBuilder.Append(((float)this.allocRate / 1000000f).ToString("0.0"));
  49. stringBuilder.Append("mb\n");
  50. stringBuilder.Append("Collection frequency\t");
  51. stringBuilder.Append(this.delta.ToString("0.00"));
  52. stringBuilder.Append("s\n");
  53. stringBuilder.Append("Last collect delta\t");
  54. stringBuilder.Append(this.lastDeltaTime.ToString("0.000"));
  55. stringBuilder.Append("s (");
  56. stringBuilder.Append((1f / this.lastDeltaTime).ToString("0.0"));
  57. stringBuilder.Append(" fps)");
  58. if (this.showFPS)
  59. {
  60. stringBuilder.Append("\n" + (1f / Time.deltaTime).ToString("0.0") + " fps");
  61. }
  62. stringBuilder.Append(string.Concat(new object[]
  63. {
  64. "\ntest x",
  65. SystemInfoHUD.vecTest.x,
  66. " y",
  67. SystemInfoHUD.vecTest.y,
  68. " z",
  69. SystemInfoHUD.vecTest.z
  70. }));
  71. for (int i = 0; i < GameMain.Instance.CharacterMgr.GetMaidCount(); i++)
  72. {
  73. Maid maid = GameMain.Instance.CharacterMgr.GetMaid(i);
  74. if (!(maid == null) && !(maid.body0 == null) && maid.body0.isLoadedBody)
  75. {
  76. stringBuilder.Append(string.Concat(new object[]
  77. {
  78. "\nMaid[",
  79. i,
  80. "] ",
  81. maid.body0.AudioMan.FileName
  82. }));
  83. }
  84. }
  85. GUI.Box(new Rect(5f, 5f, 310f, (float)(80 + ((!this.showFPS) ? 0 : 16) + 16)), string.Empty);
  86. GUI.Label(new Rect(10f, 5f, 1000f, 200f), stringBuilder.ToString());
  87. }
  88. public bool show = true;
  89. public bool showFPS;
  90. public bool showInEditor;
  91. public static Vector3 vecTest;
  92. private float lastCollect;
  93. private float lastCollectNum;
  94. private float delta;
  95. private float lastDeltaTime;
  96. private int allocRate;
  97. private int lastAllocMemory;
  98. private float lastAllocSet = -9999f;
  99. private int allocMem;
  100. private int collectAlloc;
  101. private int peakAlloc;
  102. }