TestReporter.cs 4.5 KB

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