TestReporter.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #if UNITY_CHANGE1 || UNITY_CHANGE2 || UNITY_CHANGE3 || UNITY_CHANGE4
  2. #warning UNITY_CHANGE has been set manually
  3. #elif UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7
  4. #define UNITY_CHANGE1
  5. #elif UNITY_5_0 || UNITY_5_1 || UNITY_5_2
  6. #define UNITY_CHANGE2
  7. #else
  8. #define UNITY_CHANGE3
  9. #endif
  10. #if UNITY_2018_3
  11. #define UNITY_CHANGE4
  12. #endif
  13. //use UNITY_CHANGE1 for unity older than "unity 5"
  14. //use UNITY_CHANGE2 for unity 5.0 -> 5.3
  15. //use UNITY_CHANGE3 for unity 5.3 (fix for new SceneManger system)
  16. //use UNITY_CHANGE4 for unity 2018.3 (Networking system)
  17. using UnityEngine;
  18. using System.Collections;
  19. using System.Threading;
  20. #if UNITY_CHANGE3
  21. using UnityEngine.SceneManagement;
  22. #endif
  23. #if UNITY_CHANGE4
  24. using UnityEngine.Networking;
  25. #endif
  26. //this script used for test purpose ,it do by default 100 logs + 100 warnings + 100 errors
  27. //so you can check the functionality of in game logs
  28. //just drop this scrip to any empty game object on first scene your game start at
  29. public class TestReporter : MonoBehaviour
  30. {
  31. public int logTestCount = 100;
  32. public int threadLogTestCount = 100;
  33. public bool logEverySecond = true;
  34. int currentLogTestCount;
  35. Reporter reporter;
  36. GUIStyle style;
  37. Rect rect1;
  38. Rect rect2;
  39. Rect rect3;
  40. Rect rect4;
  41. Rect rect5;
  42. Rect rect6;
  43. Thread thread;
  44. void Start()
  45. {
  46. Application.runInBackground = true;
  47. reporter = FindObjectOfType(typeof(Reporter)) as Reporter;
  48. Debug.Log("test long text sdf asdfg asdfg sdfgsdfg sdfg sfg" +
  49. "sdfgsdfg sdfg sdf gsdfg sfdg sf gsdfg sdfg asdfg " +
  50. "sdfgsdfg sdfg sdf gsdfg sfdg sf gsdfg sdfg asdfg " +
  51. "sdfgsdfg sdfg sdf gsdfg sfdg sf gsdfg sdfg asdfg " +
  52. "sdfgsdfg sdfg sdf gsdfg sfdg sf gsdfg sdfg asdfg " +
  53. "sdfgsdfg sdfg sdf gsdfg sfdg sf gsdfg sdfg asdfg ssssssssssssssssssssss" +
  54. "asdf asdf asdf asdf adsf \n dfgsdfg sdfg sdf gsdfg sfdg sf gsdfg sdfg asdf" +
  55. "asdf asdf asdf asdf adsf \n dfgsdfg sdfg sdf gsdfg sfdg sf gsdfg sdfg asdf" +
  56. "asdf asdf asdf asdf adsf \n dfgsdfg sdfg sdf gsdfg sfdg sf gsdfg sdfg asdf" +
  57. "asdf asdf asdf asdf adsf \n dfgsdfg sdfg sdf gsdfg sfdg sf gsdfg sdfg asdf" +
  58. "asdf asdf asdf asdf adsf \n dfgsdfg sdfg sdf gsdfg sfdg sf gsdfg sdfg asdf");
  59. style = new GUIStyle();
  60. style.alignment = TextAnchor.MiddleCenter;
  61. style.normal.textColor = Color.white;
  62. style.wordWrap = true;
  63. for (int i = 0; i < 10; i++) {
  64. Debug.Log("Test Collapsed log");
  65. Debug.LogWarning("Test Collapsed Warning");
  66. Debug.LogError("Test Collapsed Error");
  67. }
  68. for (int i = 0; i < 10; i++) {
  69. Debug.Log("Test Collapsed log");
  70. Debug.LogWarning("Test Collapsed Warning");
  71. Debug.LogError("Test Collapsed Error");
  72. }
  73. rect1 = new Rect(Screen.width / 2 - 120, Screen.height / 2 - 225, 240, 50);
  74. rect2 = new Rect(Screen.width / 2 - 120, Screen.height / 2 - 175, 240, 100);
  75. rect3 = new Rect(Screen.width / 2 - 120, Screen.height / 2 - 50, 240, 50);
  76. rect4 = new Rect(Screen.width / 2 - 120, Screen.height / 2, 240, 50);
  77. rect5 = new Rect(Screen.width / 2 - 120, Screen.height / 2 + 50, 240, 50);
  78. rect6 = new Rect(Screen.width / 2 - 120, Screen.height / 2 + 100, 240, 50);
  79. thread = new Thread(new ThreadStart(threadLogTest));
  80. thread.Start();
  81. }
  82. void OnDestroy()
  83. {
  84. thread.Abort();
  85. }
  86. void threadLogTest()
  87. {
  88. for (int i = 0; i < threadLogTestCount; i++) {
  89. Debug.Log("Test Log from Thread");
  90. Debug.LogWarning("Test Warning from Thread");
  91. Debug.LogError("Test Error from Thread");
  92. }
  93. }
  94. float elapsed;
  95. void Update()
  96. {
  97. int drawn = 0;
  98. while (currentLogTestCount < logTestCount && drawn < 10) {
  99. Debug.Log("Test Log " + currentLogTestCount);
  100. Debug.LogError("Test LogError " + currentLogTestCount);
  101. Debug.LogWarning("Test LogWarning " + currentLogTestCount);
  102. drawn++;
  103. currentLogTestCount++;
  104. }
  105. elapsed += Time.deltaTime;
  106. if (elapsed >= 1) {
  107. elapsed = 0;
  108. Debug.Log("One Second Passed");
  109. }
  110. }
  111. void OnGUI()
  112. {
  113. if (reporter && !reporter.show) {
  114. GUI.Label(rect1, "Draw circle on screen to show logs", style);
  115. GUI.Label(rect2, "To use Reporter just create reporter from reporter menu at first scene your game start", style);
  116. if (GUI.Button(rect3, "Load ReporterScene")) {
  117. #if UNITY_CHANGE3
  118. SceneManager.LoadScene("ReporterScene");
  119. #else
  120. Application.LoadLevel("ReporterScene");
  121. #endif
  122. }
  123. if (GUI.Button(rect4, "Load test1")) {
  124. #if UNITY_CHANGE3
  125. SceneManager.LoadScene("test1");
  126. #else
  127. Application.LoadLevel("test1");
  128. #endif
  129. }
  130. if (GUI.Button(rect5, "Load test2")) {
  131. #if UNITY_CHANGE3
  132. SceneManager.LoadScene("test2");
  133. #else
  134. Application.LoadLevel("test2");
  135. #endif
  136. }
  137. GUI.Label(rect6, "fps : " + reporter.fps.ToString("0.0"), style);
  138. }
  139. }
  140. }