驱蚊app
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 

2146 行
65 KiB

  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_OR_NEWER
  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.IO;
  19. using System.Collections;
  20. using System.Collections.Generic;
  21. #if UNITY_CHANGE3
  22. using UnityEngine.SceneManagement;
  23. #endif
  24. #if UNITY_CHANGE4
  25. using UnityEngine.Networking;
  26. #endif
  27. [System.Serializable]
  28. public class Images
  29. {
  30. public Texture2D clearImage;
  31. public Texture2D collapseImage;
  32. public Texture2D clearOnNewSceneImage;
  33. public Texture2D showTimeImage;
  34. public Texture2D showSceneImage;
  35. public Texture2D userImage;
  36. public Texture2D showMemoryImage;
  37. public Texture2D softwareImage;
  38. public Texture2D dateImage;
  39. public Texture2D showFpsImage;
  40. public Texture2D infoImage;
  41. public Texture2D saveLogsImage;
  42. public Texture2D searchImage;
  43. public Texture2D copyImage;
  44. public Texture2D copyAllImage;
  45. public Texture2D closeImage;
  46. public Texture2D buildFromImage;
  47. public Texture2D systemInfoImage;
  48. public Texture2D graphicsInfoImage;
  49. public Texture2D backImage;
  50. public Texture2D logImage;
  51. public Texture2D warningImage;
  52. public Texture2D errorImage;
  53. public Texture2D barImage;
  54. public Texture2D button_activeImage;
  55. public Texture2D even_logImage;
  56. public Texture2D odd_logImage;
  57. public Texture2D selectedImage;
  58. public GUISkin reporterScrollerSkin;
  59. }
  60. //To use Reporter just create reporter from menu (Reporter->Create) at first scene your game start.
  61. //then set the ” Scrip execution order ” in (Edit -> Project Settings ) of Reporter.cs to be the highest.
  62. //Now to view logs all what you have to do is to make a circle gesture using your mouse (click and drag)
  63. //or your finger (touch and drag) on the screen to show all these logs
  64. //no coding is required
  65. public class Reporter : MonoBehaviour
  66. {
  67. public enum _LogType
  68. {
  69. Assert = LogType.Assert,
  70. Error = LogType.Error,
  71. Exception = LogType.Exception,
  72. Log = LogType.Log,
  73. Warning = LogType.Warning,
  74. }
  75. public class Sample
  76. {
  77. public float time;
  78. public byte loadedScene;
  79. public float memory;
  80. public float fps;
  81. public string fpsText;
  82. public static float MemSize()
  83. {
  84. float s = sizeof(float) + sizeof(byte) + sizeof(float) + sizeof(float);
  85. return s;
  86. }
  87. public string GetSceneName()
  88. {
  89. if (loadedScene == 255)
  90. return "AssetBundleScene";
  91. return scenes[loadedScene];
  92. }
  93. }
  94. List<Sample> samples = new List<Sample>();
  95. public class Log
  96. {
  97. public int count = 1;
  98. public _LogType logType;
  99. public string condition;
  100. public string stacktrace;
  101. public int sampleId;
  102. //public string objectName="" ;//object who send error
  103. //public string rootName =""; //root of object send error
  104. public Log CreateCopy()
  105. {
  106. return (Log)this.MemberwiseClone();
  107. }
  108. public float GetMemoryUsage()
  109. {
  110. return (float)(sizeof(int) +
  111. sizeof(_LogType) +
  112. condition.Length * sizeof(char) +
  113. stacktrace.Length * sizeof(char) +
  114. sizeof(int));
  115. }
  116. }
  117. //contains all uncollapsed log
  118. List<Log> logs = new List<Log>();
  119. //contains all collapsed logs
  120. List<Log> collapsedLogs = new List<Log>();
  121. //contain logs which should only appear to user , for example if you switch off show logs + switch off show warnings
  122. //and your mode is collapse,then this list will contains only collapsed errors
  123. List<Log> currentLog = new List<Log>();
  124. //used to check if the new coming logs is already exist or new one
  125. MultiKeyDictionary<string, string, Log> logsDic = new MultiKeyDictionary<string, string, Log>();
  126. //to save memory
  127. Dictionary<string, string> cachedString = new Dictionary<string, string>();
  128. [HideInInspector]
  129. //show hide In Game Logs
  130. public bool show = false;
  131. //collapse logs
  132. bool collapse;
  133. //to decide if you want to clean logs for new loaded scene
  134. bool clearOnNewSceneLoaded;
  135. bool showTime;
  136. bool showScene;
  137. bool showMemory;
  138. bool showFps;
  139. bool showGraph;
  140. //show or hide logs
  141. bool showLog = true;
  142. //show or hide warnings
  143. bool showWarning = true;
  144. //show or hide errors
  145. bool showError = true;
  146. //total number of logs
  147. int numOfLogs = 0;
  148. //total number of warnings
  149. int numOfLogsWarning = 0;
  150. //total number of errors
  151. int numOfLogsError = 0;
  152. //total number of collapsed logs
  153. int numOfCollapsedLogs = 0;
  154. //total number of collapsed warnings
  155. int numOfCollapsedLogsWarning = 0;
  156. //total number of collapsed errors
  157. int numOfCollapsedLogsError = 0;
  158. //maximum number of allowed logs to view
  159. //public int maxAllowedLog = 1000 ;
  160. bool showClearOnNewSceneLoadedButton = true;
  161. bool showTimeButton = true;
  162. bool showSceneButton = true;
  163. bool showMemButton = true;
  164. bool showFpsButton = true;
  165. bool showSearchText = true;
  166. bool showCopyButton = true;
  167. bool showCopyAllButton = true;
  168. bool showSaveButton = true;
  169. string buildDate;
  170. string logDate;
  171. float logsMemUsage;
  172. float graphMemUsage;
  173. public float TotalMemUsage
  174. {
  175. get
  176. {
  177. return logsMemUsage + graphMemUsage;
  178. }
  179. }
  180. float gcTotalMemory;
  181. public string UserData = "";
  182. //frame rate per second
  183. public float fps;
  184. public string fpsText;
  185. //List<Texture2D> snapshots = new List<Texture2D>() ;
  186. enum ReportView
  187. {
  188. None,
  189. Logs,
  190. Info,
  191. Snapshot,
  192. }
  193. ReportView currentView = ReportView.Logs;
  194. enum DetailView
  195. {
  196. None,
  197. StackTrace,
  198. Graph,
  199. }
  200. //used to check if you have In Game Logs multiple time in different scene
  201. //only one should work and other should be deleted
  202. static bool created = false;
  203. //public delegate void OnLogHandler( string condition, string stack-trace, LogType type );
  204. //public event OnLogHandler OnLog ;
  205. public Images images;
  206. // gui
  207. GUIContent clearContent;
  208. GUIContent collapseContent;
  209. GUIContent clearOnNewSceneContent;
  210. GUIContent showTimeContent;
  211. GUIContent showSceneContent;
  212. GUIContent userContent;
  213. GUIContent showMemoryContent;
  214. GUIContent softwareContent;
  215. GUIContent dateContent;
  216. GUIContent showFpsContent;
  217. //GUIContent graphContent;
  218. GUIContent infoContent;
  219. GUIContent saveLogsContent;
  220. GUIContent searchContent;
  221. GUIContent copyContent;
  222. GUIContent copyAllContent;
  223. GUIContent closeContent;
  224. GUIContent buildFromContent;
  225. GUIContent systemInfoContent;
  226. GUIContent graphicsInfoContent;
  227. GUIContent backContent;
  228. //GUIContent cameraContent;
  229. GUIContent logContent;
  230. GUIContent warningContent;
  231. GUIContent errorContent;
  232. GUIStyle barStyle;
  233. GUIStyle buttonActiveStyle;
  234. GUIStyle nonStyle;
  235. GUIStyle lowerLeftFontStyle;
  236. GUIStyle backStyle;
  237. GUIStyle evenLogStyle;
  238. GUIStyle oddLogStyle;
  239. GUIStyle logButtonStyle;
  240. GUIStyle selectedLogStyle;
  241. GUIStyle selectedLogFontStyle;
  242. GUIStyle stackLabelStyle;
  243. GUIStyle scrollerStyle;
  244. GUIStyle searchStyle;
  245. GUIStyle sliderBackStyle;
  246. GUIStyle sliderThumbStyle;
  247. GUISkin toolbarScrollerSkin;
  248. GUISkin logScrollerSkin;
  249. GUISkin graphScrollerSkin;
  250. public Vector2 size = new Vector2(32, 32);
  251. public float maxSize = 20;
  252. public int numOfCircleToShow = 1;
  253. static string[] scenes;
  254. string currentScene;
  255. string filterText = "";
  256. string deviceModel;
  257. string deviceType;
  258. string deviceName;
  259. string graphicsMemorySize;
  260. #if !UNITY_CHANGE1
  261. string maxTextureSize;
  262. #endif
  263. string systemMemorySize;
  264. void Awake()
  265. {
  266. if (!Initialized)
  267. Initialize();
  268. #if UNITY_CHANGE3
  269. SceneManager.sceneLoaded += _OnLevelWasLoaded;
  270. #endif
  271. }
  272. private void OnDestroy()
  273. {
  274. #if UNITY_CHANGE3
  275. SceneManager.sceneLoaded -= _OnLevelWasLoaded;
  276. #endif
  277. }
  278. void OnEnable()
  279. {
  280. if (logs.Count == 0)//if recompile while in play mode
  281. clear();
  282. }
  283. void OnDisable()
  284. {
  285. }
  286. void addSample()
  287. {
  288. Sample sample = new Sample();
  289. sample.fps = fps;
  290. sample.fpsText = fpsText;
  291. #if UNITY_CHANGE3
  292. sample.loadedScene = (byte)SceneManager.GetActiveScene().buildIndex;
  293. #else
  294. sample.loadedScene = (byte)Application.loadedLevel;
  295. #endif
  296. sample.time = Time.realtimeSinceStartup;
  297. sample.memory = gcTotalMemory;
  298. samples.Add(sample);
  299. graphMemUsage = (samples.Count * Sample.MemSize()) / 1024 / 1024;
  300. }
  301. public bool Initialized = false;
  302. public void Initialize()
  303. {
  304. if (!created) {
  305. try {
  306. gameObject.SendMessage("OnPreStart");
  307. }
  308. catch (System.Exception e) {
  309. Debug.LogException(e);
  310. }
  311. #if UNITY_CHANGE3
  312. scenes = new string[ SceneManager.sceneCountInBuildSettings ];
  313. currentScene = SceneManager.GetActiveScene().name;
  314. #else
  315. scenes = new string[Application.levelCount];
  316. currentScene = Application.loadedLevelName;
  317. #endif
  318. DontDestroyOnLoad(gameObject);
  319. #if UNITY_CHANGE1
  320. Application.RegisterLogCallback (new Application.LogCallback (CaptureLog));
  321. Application.RegisterLogCallbackThreaded (new Application.LogCallback (CaptureLogThread));
  322. #else
  323. //Application.logMessageReceived += CaptureLog ;
  324. Application.logMessageReceivedThreaded += CaptureLogThread;
  325. #endif
  326. created = true;
  327. //addSample();
  328. }
  329. else {
  330. Debug.LogWarning("tow manager is exists delete the second");
  331. DestroyImmediate(gameObject, true);
  332. return;
  333. }
  334. //initialize gui and styles for gui purpose
  335. clearContent = new GUIContent("", images.clearImage, "Clear logs");
  336. collapseContent = new GUIContent("", images.collapseImage, "Collapse logs");
  337. clearOnNewSceneContent = new GUIContent("", images.clearOnNewSceneImage, "Clear logs on new scene loaded");
  338. showTimeContent = new GUIContent("", images.showTimeImage, "Show Hide Time");
  339. showSceneContent = new GUIContent("", images.showSceneImage, "Show Hide Scene");
  340. showMemoryContent = new GUIContent("", images.showMemoryImage, "Show Hide Memory");
  341. softwareContent = new GUIContent("", images.softwareImage, "Software");
  342. dateContent = new GUIContent("", images.dateImage, "Date");
  343. showFpsContent = new GUIContent("", images.showFpsImage, "Show Hide fps");
  344. infoContent = new GUIContent("", images.infoImage, "Information about application");
  345. saveLogsContent = new GUIContent("", images.saveLogsImage, "Save logs to device");
  346. searchContent = new GUIContent("", images.searchImage, "Search for logs");
  347. copyContent = new GUIContent("", images.copyImage, "Copy log to clipboard");
  348. copyAllContent = new GUIContent("", images.copyAllImage, "Copy all logs to clipboard");
  349. closeContent = new GUIContent("", images.closeImage, "Hide logs");
  350. userContent = new GUIContent("", images.userImage, "User");
  351. buildFromContent = new GUIContent("", images.buildFromImage, "Build From");
  352. systemInfoContent = new GUIContent("", images.systemInfoImage, "System Info");
  353. graphicsInfoContent = new GUIContent("", images.graphicsInfoImage, "Graphics Info");
  354. backContent = new GUIContent("", images.backImage, "Back");
  355. //snapshotContent = new GUIContent("",images.cameraImage,"show or hide logs");
  356. logContent = new GUIContent("", images.logImage, "show or hide logs");
  357. warningContent = new GUIContent("", images.warningImage, "show or hide warnings");
  358. errorContent = new GUIContent("", images.errorImage, "show or hide errors");
  359. currentView = (ReportView)PlayerPrefs.GetInt("Reporter_currentView", 1);
  360. show = (PlayerPrefs.GetInt("Reporter_show") == 1) ? true : false;
  361. collapse = (PlayerPrefs.GetInt("Reporter_collapse") == 1) ? true : false;
  362. clearOnNewSceneLoaded = (PlayerPrefs.GetInt("Reporter_clearOnNewSceneLoaded") == 1) ? true : false;
  363. showTime = (PlayerPrefs.GetInt("Reporter_showTime") == 1) ? true : false;
  364. showScene = (PlayerPrefs.GetInt("Reporter_showScene") == 1) ? true : false;
  365. showMemory = (PlayerPrefs.GetInt("Reporter_showMemory") == 1) ? true : false;
  366. showFps = (PlayerPrefs.GetInt("Reporter_showFps") == 1) ? true : false;
  367. showGraph = (PlayerPrefs.GetInt("Reporter_showGraph") == 1) ? true : false;
  368. showLog = (PlayerPrefs.GetInt("Reporter_showLog", 1) == 1) ? true : false;
  369. showWarning = (PlayerPrefs.GetInt("Reporter_showWarning", 1) == 1) ? true : false;
  370. showError = (PlayerPrefs.GetInt("Reporter_showError", 1) == 1) ? true : false;
  371. filterText = PlayerPrefs.GetString("Reporter_filterText");
  372. size.x = size.y = PlayerPrefs.GetFloat("Reporter_size", 32);
  373. showClearOnNewSceneLoadedButton = (PlayerPrefs.GetInt("Reporter_showClearOnNewSceneLoadedButton", 1) == 1) ? true : false;
  374. showTimeButton = (PlayerPrefs.GetInt("Reporter_showTimeButton", 1) == 1) ? true : false;
  375. showSceneButton = (PlayerPrefs.GetInt("Reporter_showSceneButton", 1) == 1) ? true : false;
  376. showMemButton = (PlayerPrefs.GetInt("Reporter_showMemButton", 1) == 1) ? true : false;
  377. showFpsButton = (PlayerPrefs.GetInt("Reporter_showFpsButton", 1) == 1) ? true : false;
  378. showSearchText = (PlayerPrefs.GetInt("Reporter_showSearchText", 1) == 1) ? true : false;
  379. showCopyButton = (PlayerPrefs.GetInt("Reporter_showCopyButton", 1) == 1) ? true : false;
  380. showCopyAllButton = (PlayerPrefs.GetInt("Reporter_showCopyAllButton", 1) == 1) ? true : false;
  381. showSaveButton = (PlayerPrefs.GetInt("Reporter_showSaveButton", 1) == 1) ? true : false;
  382. initializeStyle();
  383. Initialized = true;
  384. if (show) {
  385. doShow();
  386. }
  387. deviceModel = SystemInfo.deviceModel.ToString();
  388. deviceType = SystemInfo.deviceType.ToString();
  389. deviceName = SystemInfo.deviceName.ToString();
  390. graphicsMemorySize = SystemInfo.graphicsMemorySize.ToString();
  391. #if !UNITY_CHANGE1
  392. maxTextureSize = SystemInfo.maxTextureSize.ToString();
  393. #endif
  394. systemMemorySize = SystemInfo.systemMemorySize.ToString();
  395. }
  396. void initializeStyle()
  397. {
  398. int paddingX = (int)(size.x * 0.2f);
  399. int paddingY = (int)(size.y * 0.2f);
  400. nonStyle = new GUIStyle();
  401. nonStyle.clipping = TextClipping.Clip;
  402. nonStyle.border = new RectOffset(0, 0, 0, 0);
  403. nonStyle.normal.background = null;
  404. nonStyle.fontSize = (int)(size.y / 2);
  405. nonStyle.alignment = TextAnchor.MiddleCenter;
  406. lowerLeftFontStyle = new GUIStyle();
  407. lowerLeftFontStyle.clipping = TextClipping.Clip;
  408. lowerLeftFontStyle.border = new RectOffset(0, 0, 0, 0);
  409. lowerLeftFontStyle.normal.background = null;
  410. lowerLeftFontStyle.fontSize = (int)(size.y / 2);
  411. lowerLeftFontStyle.fontStyle = FontStyle.Bold;
  412. lowerLeftFontStyle.alignment = TextAnchor.LowerLeft;
  413. barStyle = new GUIStyle();
  414. barStyle.border = new RectOffset(1, 1, 1, 1);
  415. barStyle.normal.background = images.barImage;
  416. barStyle.active.background = images.button_activeImage;
  417. barStyle.alignment = TextAnchor.MiddleCenter;
  418. barStyle.margin = new RectOffset(1, 1, 1, 1);
  419. //barStyle.padding = new RectOffset(paddingX,paddingX,paddingY,paddingY);
  420. //barStyle.wordWrap = true ;
  421. barStyle.clipping = TextClipping.Clip;
  422. barStyle.fontSize = (int)(size.y / 2);
  423. buttonActiveStyle = new GUIStyle();
  424. buttonActiveStyle.border = new RectOffset(1, 1, 1, 1);
  425. buttonActiveStyle.normal.background = images.button_activeImage;
  426. buttonActiveStyle.alignment = TextAnchor.MiddleCenter;
  427. buttonActiveStyle.margin = new RectOffset(1, 1, 1, 1);
  428. //buttonActiveStyle.padding = new RectOffset(4,4,4,4);
  429. buttonActiveStyle.fontSize = (int)(size.y / 2);
  430. backStyle = new GUIStyle();
  431. backStyle.normal.background = images.even_logImage;
  432. backStyle.clipping = TextClipping.Clip;
  433. backStyle.fontSize = (int)(size.y / 2);
  434. evenLogStyle = new GUIStyle();
  435. evenLogStyle.normal.background = images.even_logImage;
  436. evenLogStyle.fixedHeight = size.y;
  437. evenLogStyle.clipping = TextClipping.Clip;
  438. evenLogStyle.alignment = TextAnchor.UpperLeft;
  439. evenLogStyle.imagePosition = ImagePosition.ImageLeft;
  440. evenLogStyle.fontSize = (int)(size.y / 2);
  441. //evenLogStyle.wordWrap = true;
  442. oddLogStyle = new GUIStyle();
  443. oddLogStyle.normal.background = images.odd_logImage;
  444. oddLogStyle.fixedHeight = size.y;
  445. oddLogStyle.clipping = TextClipping.Clip;
  446. oddLogStyle.alignment = TextAnchor.UpperLeft;
  447. oddLogStyle.imagePosition = ImagePosition.ImageLeft;
  448. oddLogStyle.fontSize = (int)(size.y / 2);
  449. //oddLogStyle.wordWrap = true ;
  450. logButtonStyle = new GUIStyle();
  451. //logButtonStyle.wordWrap = true;
  452. logButtonStyle.fixedHeight = size.y;
  453. logButtonStyle.clipping = TextClipping.Clip;
  454. logButtonStyle.alignment = TextAnchor.UpperLeft;
  455. //logButtonStyle.imagePosition = ImagePosition.ImageLeft ;
  456. //logButtonStyle.wordWrap = true;
  457. logButtonStyle.fontSize = (int)(size.y / 2);
  458. logButtonStyle.padding = new RectOffset(paddingX, paddingX, paddingY, paddingY);
  459. selectedLogStyle = new GUIStyle();
  460. selectedLogStyle.normal.background = images.selectedImage;
  461. selectedLogStyle.fixedHeight = size.y;
  462. selectedLogStyle.clipping = TextClipping.Clip;
  463. selectedLogStyle.alignment = TextAnchor.UpperLeft;
  464. selectedLogStyle.normal.textColor = Color.white;
  465. //selectedLogStyle.wordWrap = true;
  466. selectedLogStyle.fontSize = (int)(size.y / 2);
  467. selectedLogFontStyle = new GUIStyle();
  468. selectedLogFontStyle.normal.background = images.selectedImage;
  469. selectedLogFontStyle.fixedHeight = size.y;
  470. selectedLogFontStyle.clipping = TextClipping.Clip;
  471. selectedLogFontStyle.alignment = TextAnchor.UpperLeft;
  472. selectedLogFontStyle.normal.textColor = Color.white;
  473. //selectedLogStyle.wordWrap = true;
  474. selectedLogFontStyle.fontSize = (int)(size.y / 2);
  475. selectedLogFontStyle.padding = new RectOffset(paddingX, paddingX, paddingY, paddingY);
  476. stackLabelStyle = new GUIStyle();
  477. stackLabelStyle.wordWrap = true;
  478. stackLabelStyle.fontSize = (int)(size.y / 2);
  479. stackLabelStyle.padding = new RectOffset(paddingX, paddingX, paddingY, paddingY);
  480. scrollerStyle = new GUIStyle();
  481. scrollerStyle.normal.background = images.barImage;
  482. searchStyle = new GUIStyle();
  483. searchStyle.clipping = TextClipping.Clip;
  484. searchStyle.alignment = TextAnchor.LowerCenter;
  485. searchStyle.fontSize = (int)(size.y / 2);
  486. searchStyle.wordWrap = true;
  487. sliderBackStyle = new GUIStyle();
  488. sliderBackStyle.normal.background = images.barImage;
  489. sliderBackStyle.fixedHeight = size.y;
  490. sliderBackStyle.border = new RectOffset(1, 1, 1, 1);
  491. sliderThumbStyle = new GUIStyle();
  492. sliderThumbStyle.normal.background = images.selectedImage;
  493. sliderThumbStyle.fixedWidth = size.x;
  494. GUISkin skin = images.reporterScrollerSkin;
  495. toolbarScrollerSkin = (GUISkin)GameObject.Instantiate(skin);
  496. toolbarScrollerSkin.verticalScrollbar.fixedWidth = 0f;
  497. toolbarScrollerSkin.horizontalScrollbar.fixedHeight = 0f;
  498. toolbarScrollerSkin.verticalScrollbarThumb.fixedWidth = 0f;
  499. toolbarScrollerSkin.horizontalScrollbarThumb.fixedHeight = 0f;
  500. logScrollerSkin = (GUISkin)GameObject.Instantiate(skin);
  501. logScrollerSkin.verticalScrollbar.fixedWidth = size.x * 2f;
  502. logScrollerSkin.horizontalScrollbar.fixedHeight = 0f;
  503. logScrollerSkin.verticalScrollbarThumb.fixedWidth = size.x * 2f;
  504. logScrollerSkin.horizontalScrollbarThumb.fixedHeight = 0f;
  505. graphScrollerSkin = (GUISkin)GameObject.Instantiate(skin);
  506. graphScrollerSkin.verticalScrollbar.fixedWidth = 0f;
  507. graphScrollerSkin.horizontalScrollbar.fixedHeight = size.x * 2f;
  508. graphScrollerSkin.verticalScrollbarThumb.fixedWidth = 0f;
  509. graphScrollerSkin.horizontalScrollbarThumb.fixedHeight = size.x * 2f;
  510. //inGameLogsScrollerSkin.verticalScrollbarThumb.fixedWidth = size.x * 2;
  511. //inGameLogsScrollerSkin.verticalScrollbar.fixedWidth = size.x * 2;
  512. }
  513. void Start()
  514. {
  515. logDate = System.DateTime.Now.ToString();
  516. StartCoroutine("readInfo");
  517. }
  518. //clear all logs
  519. void clear()
  520. {
  521. logs.Clear();
  522. collapsedLogs.Clear();
  523. currentLog.Clear();
  524. logsDic.Clear();
  525. //selectedIndex = -1;
  526. selectedLog = null;
  527. numOfLogs = 0;
  528. numOfLogsWarning = 0;
  529. numOfLogsError = 0;
  530. numOfCollapsedLogs = 0;
  531. numOfCollapsedLogsWarning = 0;
  532. numOfCollapsedLogsError = 0;
  533. logsMemUsage = 0;
  534. graphMemUsage = 0;
  535. samples.Clear();
  536. System.GC.Collect();
  537. selectedLog = null;
  538. }
  539. Rect screenRect = Rect.zero;
  540. Rect toolBarRect = Rect.zero;
  541. Rect logsRect = Rect.zero;
  542. Rect stackRect = Rect.zero;
  543. Rect graphRect = Rect.zero;
  544. Rect graphMinRect = Rect.zero;
  545. Rect graphMaxRect = Rect.zero;
  546. Rect buttomRect = Rect.zero ;
  547. Vector2 stackRectTopLeft;
  548. Rect detailRect = Rect.zero;
  549. Vector2 scrollPosition;
  550. Vector2 scrollPosition2;
  551. Vector2 toolbarScrollPosition;
  552. //int selectedIndex = -1;
  553. Log selectedLog;
  554. float toolbarOldDrag = 0;
  555. float oldDrag;
  556. float oldDrag2;
  557. float oldDrag3;
  558. int startIndex;
  559. //calculate what is the currentLog : collapsed or not , hide or view warnings ......
  560. void calculateCurrentLog()
  561. {
  562. bool filter = !string.IsNullOrEmpty(filterText);
  563. string _filterText = "";
  564. if (filter)
  565. _filterText = filterText.ToLower();
  566. currentLog.Clear();
  567. if (collapse) {
  568. for (int i = 0; i < collapsedLogs.Count; i++) {
  569. Log log = collapsedLogs[i];
  570. if (log.logType == _LogType.Log && !showLog)
  571. continue;
  572. if (log.logType == _LogType.Warning && !showWarning)
  573. continue;
  574. if (log.logType == _LogType.Error && !showError)
  575. continue;
  576. if (log.logType == _LogType.Assert && !showError)
  577. continue;
  578. if (log.logType == _LogType.Exception && !showError)
  579. continue;
  580. if (filter) {
  581. if (log.condition.ToLower().Contains(_filterText))
  582. currentLog.Add(log);
  583. }
  584. else {
  585. currentLog.Add(log);
  586. }
  587. }
  588. }
  589. else {
  590. for (int i = 0; i < logs.Count; i++) {
  591. Log log = logs[i];
  592. if (log.logType == _LogType.Log && !showLog)
  593. continue;
  594. if (log.logType == _LogType.Warning && !showWarning)
  595. continue;
  596. if (log.logType == _LogType.Error && !showError)
  597. continue;
  598. if (log.logType == _LogType.Assert && !showError)
  599. continue;
  600. if (log.logType == _LogType.Exception && !showError)
  601. continue;
  602. if (filter) {
  603. if (log.condition.ToLower().Contains(_filterText))
  604. currentLog.Add(log);
  605. }
  606. else {
  607. currentLog.Add(log);
  608. }
  609. }
  610. }
  611. if (selectedLog != null) {
  612. int newSelectedIndex = currentLog.IndexOf(selectedLog);
  613. if (newSelectedIndex == -1) {
  614. Log collapsedSelected = logsDic[selectedLog.condition][selectedLog.stacktrace];
  615. newSelectedIndex = currentLog.IndexOf(collapsedSelected);
  616. if (newSelectedIndex != -1)
  617. scrollPosition.y = newSelectedIndex * size.y;
  618. }
  619. else {
  620. scrollPosition.y = newSelectedIndex * size.y;
  621. }
  622. }
  623. }
  624. Rect countRect = Rect.zero;
  625. Rect timeRect = Rect.zero;
  626. Rect timeLabelRect = Rect.zero;
  627. Rect sceneRect = Rect.zero;
  628. Rect sceneLabelRect = Rect.zero;
  629. Rect memoryRect = Rect.zero;
  630. Rect memoryLabelRect = Rect.zero;
  631. Rect fpsRect = Rect.zero;
  632. Rect fpsLabelRect = Rect.zero;
  633. GUIContent tempContent = new GUIContent();
  634. Vector2 infoScrollPosition;
  635. Vector2 oldInfoDrag;
  636. void DrawInfo()
  637. {
  638. GUILayout.BeginArea(screenRect, backStyle);
  639. Vector2 drag = getDrag();
  640. if ((drag.x != 0) && (downPos != Vector2.zero)) {
  641. infoScrollPosition.x -= (drag.x - oldInfoDrag.x);
  642. }
  643. if ((drag.y != 0) && (downPos != Vector2.zero)) {
  644. infoScrollPosition.y += (drag.y - oldInfoDrag.y);
  645. }
  646. oldInfoDrag = drag;
  647. GUI.skin = toolbarScrollerSkin;
  648. infoScrollPosition = GUILayout.BeginScrollView(infoScrollPosition);
  649. GUILayout.Space(size.x);
  650. GUILayout.BeginHorizontal();
  651. GUILayout.Space(size.x);
  652. GUILayout.Box(buildFromContent, nonStyle, GUILayout.Width(size.x), GUILayout.Height(size.y));
  653. GUILayout.Space(size.x);
  654. GUILayout.Label(buildDate, nonStyle, GUILayout.Height(size.y));
  655. GUILayout.FlexibleSpace();
  656. GUILayout.EndHorizontal();
  657. GUILayout.BeginHorizontal();
  658. GUILayout.Space(size.x);
  659. GUILayout.Box(systemInfoContent, nonStyle, GUILayout.Width(size.x), GUILayout.Height(size.y));
  660. GUILayout.Space(size.x);
  661. GUILayout.Label(deviceModel, nonStyle, GUILayout.Height(size.y));
  662. GUILayout.Space(size.x);
  663. GUILayout.Label(deviceType, nonStyle, GUILayout.Height(size.y));
  664. GUILayout.Space(size.x);
  665. GUILayout.Label(deviceName, nonStyle, GUILayout.Height(size.y));
  666. GUILayout.FlexibleSpace();
  667. GUILayout.EndHorizontal();
  668. GUILayout.BeginHorizontal();
  669. GUILayout.Space(size.x);
  670. GUILayout.Box(graphicsInfoContent, nonStyle, GUILayout.Width(size.x), GUILayout.Height(size.y));
  671. GUILayout.Space(size.x);
  672. GUILayout.Label(SystemInfo.graphicsDeviceName, nonStyle, GUILayout.Height(size.y));
  673. GUILayout.Space(size.x);
  674. GUILayout.Label(graphicsMemorySize, nonStyle, GUILayout.Height(size.y));
  675. #if !UNITY_CHANGE1
  676. GUILayout.Space(size.x);
  677. GUILayout.Label(maxTextureSize, nonStyle, GUILayout.Height(size.y));
  678. #endif
  679. GUILayout.FlexibleSpace();
  680. GUILayout.EndHorizontal();
  681. GUILayout.BeginHorizontal();
  682. GUILayout.Space(size.x);
  683. GUILayout.Space(size.x);
  684. GUILayout.Space(size.x);
  685. GUILayout.Label("Screen Width " + Screen.width, nonStyle, GUILayout.Height(size.y));
  686. GUILayout.Space(size.x);
  687. GUILayout.Label("Screen Height " + Screen.height, nonStyle, GUILayout.Height(size.y));
  688. GUILayout.FlexibleSpace();
  689. GUILayout.EndHorizontal();
  690. GUILayout.BeginHorizontal();
  691. GUILayout.Space(size.x);
  692. GUILayout.Box(showMemoryContent, nonStyle, GUILayout.Width(size.x), GUILayout.Height(size.y));
  693. GUILayout.Space(size.x);
  694. GUILayout.Label(systemMemorySize + " mb", nonStyle, GUILayout.Height(size.y));
  695. GUILayout.FlexibleSpace();
  696. GUILayout.EndHorizontal();
  697. GUILayout.BeginHorizontal();
  698. GUILayout.Space(size.x);
  699. GUILayout.Space(size.x);
  700. GUILayout.Space(size.x);
  701. GUILayout.Label("Mem Usage Of Logs " + logsMemUsage.ToString("0.000") + " mb", nonStyle, GUILayout.Height(size.y));
  702. GUILayout.Space(size.x);
  703. //GUILayout.Label( "Mem Usage Of Graph " + graphMemUsage.ToString("0.000") + " mb", nonStyle , GUILayout.Height(size.y));
  704. //GUILayout.Space( size.x);
  705. GUILayout.Label("GC Memory " + gcTotalMemory.ToString("0.000") + " mb", nonStyle, GUILayout.Height(size.y));
  706. GUILayout.FlexibleSpace();
  707. GUILayout.EndHorizontal();
  708. GUILayout.BeginHorizontal();
  709. GUILayout.Space(size.x);
  710. GUILayout.Box(softwareContent, nonStyle, GUILayout.Width(size.x), GUILayout.Height(size.y));
  711. GUILayout.Space(size.x);
  712. GUILayout.Label(SystemInfo.operatingSystem, nonStyle, GUILayout.Height(size.y));
  713. GUILayout.FlexibleSpace();
  714. GUILayout.EndHorizontal();
  715. GUILayout.BeginHorizontal();
  716. GUILayout.Space(size.x);
  717. GUILayout.Box(dateContent, nonStyle, GUILayout.Width(size.x), GUILayout.Height(size.y));
  718. GUILayout.Space(size.x);
  719. GUILayout.Label(System.DateTime.Now.ToString(), nonStyle, GUILayout.Height(size.y));
  720. GUILayout.Label(" - Application Started At " + logDate, nonStyle, GUILayout.Height(size.y));
  721. GUILayout.FlexibleSpace();
  722. GUILayout.EndHorizontal();
  723. GUILayout.BeginHorizontal();
  724. GUILayout.Space(size.x);
  725. GUILayout.Box(showTimeContent, nonStyle, GUILayout.Width(size.x), GUILayout.Height(size.y));
  726. GUILayout.Space(size.x);
  727. GUILayout.Label(Time.realtimeSinceStartup.ToString("000"), nonStyle, GUILayout.Height(size.y));
  728. GUILayout.FlexibleSpace();
  729. GUILayout.EndHorizontal();
  730. GUILayout.BeginHorizontal();
  731. GUILayout.Space(size.x);
  732. GUILayout.Box(showFpsContent, nonStyle, GUILayout.Width(size.x), GUILayout.Height(size.y));
  733. GUILayout.Space(size.x);
  734. GUILayout.Label(fpsText, nonStyle, GUILayout.Height(size.y));
  735. GUILayout.FlexibleSpace();
  736. GUILayout.EndHorizontal();
  737. GUILayout.BeginHorizontal();
  738. GUILayout.Space(size.x);
  739. GUILayout.Box(userContent, nonStyle, GUILayout.Width(size.x), GUILayout.Height(size.y));
  740. GUILayout.Space(size.x);
  741. GUILayout.Label(UserData, nonStyle, GUILayout.Height(size.y));
  742. GUILayout.FlexibleSpace();
  743. GUILayout.EndHorizontal();
  744. GUILayout.BeginHorizontal();
  745. GUILayout.Space(size.x);
  746. GUILayout.Box(showSceneContent, nonStyle, GUILayout.Width(size.x), GUILayout.Height(size.y));
  747. GUILayout.Space(size.x);
  748. GUILayout.Label(currentScene, nonStyle, GUILayout.Height(size.y));
  749. GUILayout.FlexibleSpace();
  750. GUILayout.EndHorizontal();
  751. GUILayout.BeginHorizontal();
  752. GUILayout.Space(size.x);
  753. GUILayout.Box(showSceneContent, nonStyle, GUILayout.Width(size.x), GUILayout.Height(size.y));
  754. GUILayout.Space(size.x);
  755. GUILayout.Label("Unity Version = " + Application.unityVersion, nonStyle, GUILayout.Height(size.y));
  756. GUILayout.FlexibleSpace();
  757. GUILayout.EndHorizontal();
  758. /*GUILayout.BeginHorizontal();
  759. GUILayout.Space( size.x);
  760. GUILayout.Box( graphContent ,nonStyle , GUILayout.Width(size.x) , GUILayout.Height(size.y));
  761. GUILayout.Space( size.x);
  762. GUILayout.Label( "frame " + samples.Count , nonStyle , GUILayout.Height(size.y));
  763. GUILayout.FlexibleSpace();
  764. GUILayout.EndHorizontal();*/
  765. drawInfo_enableDisableToolBarButtons();
  766. GUILayout.FlexibleSpace();
  767. GUILayout.BeginHorizontal();
  768. GUILayout.Space(size.x);
  769. GUILayout.Label("Size = " + size.x.ToString("0.0"), nonStyle, GUILayout.Height(size.y));
  770. GUILayout.Space(size.x);
  771. float _size = GUILayout.HorizontalSlider(size.x, 16, 64, sliderBackStyle, sliderThumbStyle, GUILayout.Width(Screen.width * 0.5f));
  772. if (size.x != _size) {
  773. size.x = size.y = _size;
  774. initializeStyle();
  775. }
  776. GUILayout.FlexibleSpace();
  777. GUILayout.EndHorizontal();
  778. GUILayout.BeginHorizontal();
  779. GUILayout.Space(size.x);
  780. if (GUILayout.Button(backContent, barStyle, GUILayout.Width(size.x * 2), GUILayout.Height(size.y * 2))) {
  781. currentView = ReportView.Logs;
  782. }
  783. GUILayout.FlexibleSpace();
  784. GUILayout.EndHorizontal();
  785. GUILayout.EndScrollView();
  786. GUILayout.EndArea();
  787. }
  788. void drawInfo_enableDisableToolBarButtons()
  789. {
  790. GUILayout.BeginHorizontal();
  791. GUILayout.Space(size.x);
  792. GUILayout.Label("Hide or Show tool bar buttons", nonStyle, GUILayout.Height(size.y));
  793. GUILayout.Space(size.x);
  794. GUILayout.FlexibleSpace();
  795. GUILayout.EndHorizontal();
  796. GUILayout.BeginHorizontal();
  797. GUILayout.Space(size.x);
  798. if (GUILayout.Button(clearOnNewSceneContent, (showClearOnNewSceneLoadedButton) ? buttonActiveStyle : barStyle, GUILayout.Width(size.x * 2), GUILayout.Height(size.y * 2))) {
  799. showClearOnNewSceneLoadedButton = !showClearOnNewSceneLoadedButton;
  800. }
  801. if (GUILayout.Button(showTimeContent, (showTimeButton) ? buttonActiveStyle : barStyle, GUILayout.Width(size.x * 2), GUILayout.Height(size.y * 2))) {
  802. showTimeButton = !showTimeButton;
  803. }
  804. tempRect = GUILayoutUtility.GetLastRect();
  805. GUI.Label(tempRect, Time.realtimeSinceStartup.ToString("0.0"), lowerLeftFontStyle);
  806. if (GUILayout.Button(showSceneContent, (showSceneButton) ? buttonActiveStyle : barStyle, GUILayout.Width(size.x * 2), GUILayout.Height(size.y * 2))) {
  807. showSceneButton = !showSceneButton;
  808. }
  809. tempRect = GUILayoutUtility.GetLastRect();
  810. GUI.Label(tempRect, currentScene, lowerLeftFontStyle);
  811. if (GUILayout.Button(showMemoryContent, (showMemButton) ? buttonActiveStyle : barStyle, GUILayout.Width(size.x * 2), GUILayout.Height(size.y * 2))) {
  812. showMemButton = !showMemButton;
  813. }
  814. tempRect = GUILayoutUtility.GetLastRect();
  815. GUI.Label(tempRect, gcTotalMemory.ToString("0.0"), lowerLeftFontStyle);
  816. if (GUILayout.Button(showFpsContent, (showFpsButton) ? buttonActiveStyle : barStyle, GUILayout.Width(size.x * 2), GUILayout.Height(size.y * 2))) {
  817. showFpsButton = !showFpsButton;
  818. }
  819. tempRect = GUILayoutUtility.GetLastRect();
  820. GUI.Label(tempRect, fpsText, lowerLeftFontStyle);
  821. /*if( GUILayout.Button( graphContent , (showGraph)?buttonActiveStyle:barStyle , GUILayout.Width(size.x*2) ,GUILayout.Height(size.y*2)))
  822. {
  823. showGraph = !showGraph ;
  824. }
  825. tempRect = GUILayoutUtility.GetLastRect();
  826. GUI.Label( tempRect , samples.Count.ToString() , lowerLeftFontStyle );*/
  827. if (GUILayout.Button(searchContent, (showSearchText) ? buttonActiveStyle : barStyle, GUILayout.Width(size.x * 2), GUILayout.Height(size.y * 2))) {
  828. showSearchText = !showSearchText;
  829. }
  830. if (GUILayout.Button(copyContent, (showCopyButton) ? buttonActiveStyle : barStyle, GUILayout.Width(size.x * 2), GUILayout.Height(size.y * 2)))
  831. {
  832. showCopyButton = !showCopyButton;
  833. }
  834. if (GUILayout.Button(copyAllContent, (showCopyAllButton) ? buttonActiveStyle : barStyle, GUILayout.Width(size.x * 2), GUILayout.Height(size.y * 2)))
  835. {
  836. showCopyAllButton = !showCopyAllButton;
  837. }
  838. if (GUILayout.Button(saveLogsContent, (showSaveButton) ? buttonActiveStyle : barStyle, GUILayout.Width(size.x * 2), GUILayout.Height(size.y * 2)))
  839. {
  840. showSaveButton = !showSaveButton;
  841. }
  842. tempRect = GUILayoutUtility.GetLastRect();
  843. GUI.TextField(tempRect, filterText, searchStyle);
  844. GUILayout.FlexibleSpace();
  845. GUILayout.EndHorizontal();
  846. }
  847. void DrawReport()
  848. {
  849. screenRect.x = 0f;
  850. screenRect.y = 0f;
  851. screenRect.width = Screen.width;
  852. screenRect.height = Screen.height;
  853. GUILayout.BeginArea(screenRect, backStyle);
  854. GUILayout.BeginVertical();
  855. GUILayout.FlexibleSpace();
  856. GUILayout.BeginHorizontal();
  857. GUILayout.FlexibleSpace();
  858. /*GUILayout.Box( cameraContent ,nonStyle , GUILayout.Width(size.x) , GUILayout.Height(size.y));
  859. GUILayout.FlexibleSpace();*/
  860. GUILayout.Label("Select Photo", nonStyle, GUILayout.Height(size.y));
  861. GUILayout.FlexibleSpace();
  862. GUILayout.EndHorizontal();
  863. GUILayout.BeginHorizontal();
  864. GUILayout.Label("Coming Soon", nonStyle, GUILayout.Height(size.y));
  865. GUILayout.EndHorizontal();
  866. GUILayout.BeginHorizontal();
  867. GUILayout.FlexibleSpace();
  868. if (GUILayout.Button(backContent, barStyle, GUILayout.Width(size.x), GUILayout.Height(size.y))) {
  869. currentView = ReportView.Logs;
  870. }
  871. GUILayout.FlexibleSpace();
  872. GUILayout.EndHorizontal();
  873. GUILayout.FlexibleSpace();
  874. GUILayout.EndVertical();
  875. GUILayout.EndArea();
  876. }
  877. void drawToolBar()
  878. {
  879. toolBarRect.x = 0f;
  880. toolBarRect.y = 0f;
  881. toolBarRect.width = Screen.width;
  882. toolBarRect.height = size.y * 2f;
  883. //toolbarScrollerSkin.verticalScrollbar.fixedWidth = 0f;
  884. //toolbarScrollerSkin.horizontalScrollbar.fixedHeight= 0f ;
  885. GUI.skin = toolbarScrollerSkin;
  886. Vector2 drag = getDrag();
  887. if ((drag.x != 0) && (downPos != Vector2.zero) && (downPos.y > Screen.height - size.y * 2f)) {
  888. toolbarScrollPosition.x -= (drag.x - toolbarOldDrag);
  889. }
  890. toolbarOldDrag = drag.x;
  891. GUILayout.BeginArea(toolBarRect);
  892. toolbarScrollPosition = GUILayout.BeginScrollView(toolbarScrollPosition);
  893. GUILayout.BeginHorizontal(barStyle);
  894. if (GUILayout.Button(clearContent, barStyle, GUILayout.Width(size.x * 2), GUILayout.Height(size.y * 2))) {
  895. clear();
  896. }
  897. if (GUILayout.Button(collapseContent, (collapse) ? buttonActiveStyle : barStyle, GUILayout.Width(size.x * 2), GUILayout.Height(size.y * 2))) {
  898. collapse = !collapse;
  899. calculateCurrentLog();
  900. }
  901. if (showClearOnNewSceneLoadedButton && GUILayout.Button(clearOnNewSceneContent, (clearOnNewSceneLoaded) ? buttonActiveStyle : barStyle, GUILayout.Width(size.x * 2), GUILayout.Height(size.y * 2))) {
  902. clearOnNewSceneLoaded = !clearOnNewSceneLoaded;
  903. }
  904. if (showTimeButton && GUILayout.Button(showTimeContent, (showTime) ? buttonActiveStyle : barStyle, GUILayout.Width(size.x * 2), GUILayout.Height(size.y * 2))) {
  905. showTime = !showTime;
  906. }
  907. if (showSceneButton) {
  908. tempRect = GUILayoutUtility.GetLastRect();
  909. GUI.Label(tempRect, Time.realtimeSinceStartup.ToString("0.0"), lowerLeftFontStyle);
  910. if (GUILayout.Button(showSceneContent, (showScene) ? buttonActiveStyle : barStyle, GUILayout.Width(size.x * 2), GUILayout.Height(size.y * 2))) {
  911. showScene = !showScene;
  912. }
  913. tempRect = GUILayoutUtility.GetLastRect();
  914. GUI.Label(tempRect, currentScene, lowerLeftFontStyle);
  915. }
  916. if (showMemButton) {
  917. if (GUILayout.Button(showMemoryContent, (showMemory) ? buttonActiveStyle : barStyle, GUILayout.Width(size.x * 2), GUILayout.Height(size.y * 2))) {
  918. showMemory = !showMemory;
  919. }
  920. tempRect = GUILayoutUtility.GetLastRect();
  921. GUI.Label(tempRect, gcTotalMemory.ToString("0.0"), lowerLeftFontStyle);
  922. }
  923. if (showFpsButton) {
  924. if (GUILayout.Button(showFpsContent, (showFps) ? buttonActiveStyle : barStyle, GUILayout.Width(size.x * 2), GUILayout.Height(size.y * 2))) {
  925. showFps = !showFps;
  926. }
  927. tempRect = GUILayoutUtility.GetLastRect();
  928. GUI.Label(tempRect, fpsText, lowerLeftFontStyle);
  929. }
  930. /*if( GUILayout.Button( graphContent , (showGraph)?buttonActiveStyle:barStyle , GUILayout.Width(size.x*2) ,GUILayout.Height(size.y*2)))
  931. {
  932. showGraph = !showGraph ;
  933. }
  934. tempRect = GUILayoutUtility.GetLastRect();
  935. GUI.Label( tempRect , samples.Count.ToString() , lowerLeftFontStyle );*/
  936. if (showSearchText) {
  937. GUILayout.Box(searchContent, barStyle, GUILayout.Width(size.x * 2), GUILayout.Height(size.y * 2));
  938. tempRect = GUILayoutUtility.GetLastRect();
  939. string newFilterText = GUI.TextField(tempRect, filterText, searchStyle);
  940. if (newFilterText != filterText) {
  941. filterText = newFilterText;
  942. calculateCurrentLog();
  943. }
  944. }
  945. if (showCopyButton)
  946. {
  947. if (GUILayout.Button(copyContent, barStyle, GUILayout.Width(size.x * 2), GUILayout.Height(size.y * 2)))
  948. {
  949. if (selectedLog == null)
  950. GUIUtility.systemCopyBuffer = "No log selected";
  951. else
  952. GUIUtility.systemCopyBuffer = selectedLog.condition + System.Environment.NewLine + System.Environment.NewLine + selectedLog.stacktrace;
  953. }
  954. }
  955. if (showCopyAllButton)
  956. {
  957. if (GUILayout.Button(copyAllContent, barStyle, GUILayout.Width(size.x * 2), GUILayout.Height(size.y * 2)))
  958. {
  959. string allLogsToClipboard = string.Empty;
  960. logs.ForEach(l => allLogsToClipboard += l.condition + System.Environment.NewLine + System.Environment.NewLine + l.stacktrace);
  961. if(string.IsNullOrWhiteSpace(allLogsToClipboard))
  962. GUIUtility.systemCopyBuffer = "No log selected";
  963. else
  964. GUIUtility.systemCopyBuffer = allLogsToClipboard;
  965. }
  966. }
  967. if (showSaveButton)
  968. {
  969. if (GUILayout.Button(saveLogsContent, barStyle, GUILayout.Width(size.x * 2), GUILayout.Height(size.y * 2)))
  970. {
  971. SaveLogsToDevice();
  972. }
  973. }
  974. if (GUILayout.Button(infoContent, barStyle, GUILayout.Width(size.x * 2), GUILayout.Height(size.y * 2))) {
  975. currentView = ReportView.Info;
  976. }
  977. GUILayout.FlexibleSpace();
  978. string logsText = " ";
  979. if (collapse) {
  980. logsText += numOfCollapsedLogs;
  981. }
  982. else {
  983. logsText += numOfLogs;
  984. }
  985. string logsWarningText = " ";
  986. if (collapse) {
  987. logsWarningText += numOfCollapsedLogsWarning;
  988. }
  989. else {
  990. logsWarningText += numOfLogsWarning;
  991. }
  992. string logsErrorText = " ";
  993. if (collapse) {
  994. logsErrorText += numOfCollapsedLogsError;
  995. }
  996. else {
  997. logsErrorText += numOfLogsError;
  998. }
  999. GUILayout.BeginHorizontal((showLog) ? buttonActiveStyle : barStyle);
  1000. if (GUILayout.Button(logContent, nonStyle, GUILayout.Width(size.x * 2), GUILayout.Height(size.y * 2))) {
  1001. showLog = !showLog;
  1002. calculateCurrentLog();
  1003. }
  1004. if (GUILayout.Button(logsText, nonStyle, GUILayout.Width(size.x * 2), GUILayout.Height(size.y * 2))) {
  1005. showLog = !showLog;
  1006. calculateCurrentLog();
  1007. }
  1008. GUILayout.EndHorizontal();
  1009. GUILayout.BeginHorizontal((showWarning) ? buttonActiveStyle : barStyle);
  1010. if (GUILayout.Button(warningContent, nonStyle, GUILayout.Width(size.x * 2), GUILayout.Height(size.y * 2))) {
  1011. showWarning = !showWarning;
  1012. calculateCurrentLog();
  1013. }
  1014. if (GUILayout.Button(logsWarningText, nonStyle, GUILayout.Width(size.x * 2), GUILayout.Height(size.y * 2))) {
  1015. showWarning = !showWarning;
  1016. calculateCurrentLog();
  1017. }
  1018. GUILayout.EndHorizontal();
  1019. GUILayout.BeginHorizontal((showError) ? buttonActiveStyle : nonStyle);
  1020. if (GUILayout.Button(errorContent, nonStyle, GUILayout.Width(size.x * 2), GUILayout.Height(size.y * 2))) {
  1021. showError = !showError;
  1022. calculateCurrentLog();
  1023. }
  1024. if (GUILayout.Button(logsErrorText, nonStyle, GUILayout.Width(size.x * 2), GUILayout.Height(size.y * 2))) {
  1025. showError = !showError;
  1026. calculateCurrentLog();
  1027. }
  1028. GUILayout.EndHorizontal();
  1029. if (GUILayout.Button(closeContent, barStyle, GUILayout.Width(size.x * 2), GUILayout.Height(size.y * 2))) {
  1030. show = false;
  1031. ReporterGUI gui = gameObject.GetComponent<ReporterGUI>();
  1032. DestroyImmediate(gui);
  1033. try {
  1034. gameObject.SendMessage("OnHideReporter");
  1035. }
  1036. catch (System.Exception e) {
  1037. Debug.LogException(e);
  1038. }
  1039. }
  1040. GUILayout.EndHorizontal();
  1041. GUILayout.EndScrollView();
  1042. GUILayout.EndArea();
  1043. }
  1044. Rect tempRect;
  1045. void DrawLogs()
  1046. {
  1047. GUILayout.BeginArea(logsRect, backStyle);
  1048. GUI.skin = logScrollerSkin;
  1049. //setStartPos();
  1050. Vector2 drag = getDrag();
  1051. if (drag.y != 0 && logsRect.Contains(new Vector2(downPos.x, Screen.height - downPos.y))) {
  1052. scrollPosition.y += (drag.y - oldDrag);
  1053. }
  1054. scrollPosition = GUILayout.BeginScrollView(scrollPosition);
  1055. oldDrag = drag.y;
  1056. int totalVisibleCount = (int)(Screen.height * 0.75f / size.y);
  1057. int totalCount = currentLog.Count;
  1058. /*if( totalCount < 100 )
  1059. inGameLogsScrollerSkin.verticalScrollbarThumb.fixedHeight = 0;
  1060. else
  1061. inGameLogsScrollerSkin.verticalScrollbarThumb.fixedHeight = 64;*/
  1062. totalVisibleCount = Mathf.Min(totalVisibleCount, totalCount - startIndex);
  1063. int index = 0;
  1064. int beforeHeight = (int)(startIndex * size.y);
  1065. //selectedIndex = Mathf.Clamp( selectedIndex , -1 , totalCount -1);
  1066. if (beforeHeight > 0) {
  1067. //fill invisible gap before scroller to make proper scroller pos
  1068. GUILayout.BeginHorizontal(GUILayout.Height(beforeHeight));
  1069. GUILayout.Label("---");
  1070. GUILayout.EndHorizontal();
  1071. }
  1072. int endIndex = startIndex + totalVisibleCount;
  1073. endIndex = Mathf.Clamp(endIndex, 0, totalCount);
  1074. bool scrollerVisible = (totalVisibleCount < totalCount);
  1075. for (int i = startIndex; (startIndex + index) < endIndex; i++) {
  1076. if (i >= currentLog.Count)
  1077. break;
  1078. Log log = currentLog[i];
  1079. if (log.logType == _LogType.Log && !showLog)
  1080. continue;
  1081. if (log.logType == _LogType.Warning && !showWarning)
  1082. continue;
  1083. if (log.logType == _LogType.Error && !showError)
  1084. continue;
  1085. if (log.logType == _LogType.Assert && !showError)
  1086. continue;
  1087. if (log.logType == _LogType.Exception && !showError)
  1088. continue;
  1089. if (index >= totalVisibleCount) {
  1090. break;
  1091. }
  1092. GUIContent content = null;
  1093. if (log.logType == _LogType.Log)
  1094. content = logContent;
  1095. else if (log.logType == _LogType.Warning)
  1096. content = warningContent;
  1097. else
  1098. content = errorContent;
  1099. //content.text = log.condition ;
  1100. GUIStyle currentLogStyle = ((startIndex + index) % 2 == 0) ? evenLogStyle : oddLogStyle;
  1101. if (log == selectedLog) {
  1102. //selectedLog = log ;
  1103. currentLogStyle = selectedLogStyle;
  1104. }
  1105. else {
  1106. }
  1107. tempContent.text = log.count.ToString();
  1108. float w = 0f;
  1109. if (collapse)
  1110. w = barStyle.CalcSize(tempContent).x + 3;
  1111. countRect.x = Screen.width - w;
  1112. countRect.y = size.y * i;
  1113. if (beforeHeight > 0)
  1114. countRect.y += 8;//i will check later why
  1115. countRect.width = w;
  1116. countRect.height = size.y;
  1117. if (scrollerVisible)
  1118. countRect.x -= size.x * 2;
  1119. Sample sample = samples[log.sampleId];
  1120. fpsRect = countRect;
  1121. if (showFps) {
  1122. tempContent.text = sample.fpsText;
  1123. w = currentLogStyle.CalcSize(tempContent).x + size.x;
  1124. fpsRect.x -= w;
  1125. fpsRect.width = size.x;
  1126. fpsLabelRect = fpsRect;
  1127. fpsLabelRect.x += size.x;
  1128. fpsLabelRect.width = w - size.x;
  1129. }
  1130. memoryRect = fpsRect;
  1131. if (showMemory) {
  1132. tempContent.text = sample.memory.ToString("0.000");
  1133. w = currentLogStyle.CalcSize(tempContent).x + size.x;
  1134. memoryRect.x -= w;
  1135. memoryRect.width = size.x;
  1136. memoryLabelRect = memoryRect;
  1137. memoryLabelRect.x += size.x;
  1138. memoryLabelRect.width = w - size.x;
  1139. }
  1140. sceneRect = memoryRect;
  1141. if (showScene) {
  1142. tempContent.text = sample.GetSceneName();
  1143. w = currentLogStyle.CalcSize(tempContent).x + size.x;
  1144. sceneRect.x -= w;
  1145. sceneRect.width = size.x;
  1146. sceneLabelRect = sceneRect;
  1147. sceneLabelRect.x += size.x;
  1148. sceneLabelRect.width = w - size.x;
  1149. }
  1150. timeRect = sceneRect;
  1151. if (showTime) {
  1152. tempContent.text = sample.time.ToString("0.000");
  1153. w = currentLogStyle.CalcSize(tempContent).x + size.x;
  1154. timeRect.x -= w;
  1155. timeRect.width = size.x;
  1156. timeLabelRect = timeRect;
  1157. timeLabelRect.x += size.x;
  1158. timeLabelRect.width = w - size.x;
  1159. }
  1160. GUILayout.BeginHorizontal(currentLogStyle);
  1161. if (log == selectedLog) {
  1162. GUILayout.Box(content, nonStyle, GUILayout.Width(size.x), GUILayout.Height(size.y));
  1163. GUILayout.Label(log.condition, selectedLogFontStyle);
  1164. //GUILayout.FlexibleSpace();
  1165. if (showTime) {
  1166. GUI.Box(timeRect, showTimeContent, currentLogStyle);
  1167. GUI.Label(timeLabelRect, sample.time.ToString("0.000"), currentLogStyle);
  1168. }
  1169. if (showScene) {
  1170. GUI.Box(sceneRect, showSceneContent, currentLogStyle);
  1171. GUI.Label(sceneLabelRect, sample.GetSceneName(), currentLogStyle);
  1172. }
  1173. if (showMemory) {
  1174. GUI.Box(memoryRect, showMemoryContent, currentLogStyle);
  1175. GUI.Label(memoryLabelRect, sample.memory.ToString("0.000") + " mb", currentLogStyle);
  1176. }
  1177. if (showFps) {
  1178. GUI.Box(fpsRect, showFpsContent, currentLogStyle);
  1179. GUI.Label(fpsLabelRect, sample.fpsText, currentLogStyle);
  1180. }
  1181. }
  1182. else {
  1183. if (GUILayout.Button(content, nonStyle, GUILayout.Width(size.x), GUILayout.Height(size.y))) {
  1184. //selectedIndex = startIndex + index ;
  1185. selectedLog = log;
  1186. }
  1187. if (GUILayout.Button(log.condition, logButtonStyle)) {
  1188. //selectedIndex = startIndex + index ;
  1189. selectedLog = log;
  1190. }
  1191. //GUILayout.FlexibleSpace();
  1192. if (showTime) {
  1193. GUI.Box(timeRect, showTimeContent, currentLogStyle);
  1194. GUI.Label(timeLabelRect, sample.time.ToString("0.000"), currentLogStyle);
  1195. }
  1196. if (showScene) {
  1197. GUI.Box(sceneRect, showSceneContent, currentLogStyle);
  1198. GUI.Label(sceneLabelRect, sample.GetSceneName(), currentLogStyle);
  1199. }
  1200. if (showMemory) {
  1201. GUI.Box(memoryRect, showMemoryContent, currentLogStyle);
  1202. GUI.Label(memoryLabelRect, sample.memory.ToString("0.000") + " mb", currentLogStyle);
  1203. }
  1204. if (showFps) {
  1205. GUI.Box(fpsRect, showFpsContent, currentLogStyle);
  1206. GUI.Label(fpsLabelRect, sample.fpsText, currentLogStyle);
  1207. }
  1208. }
  1209. if (collapse)
  1210. GUI.Label(countRect, log.count.ToString(), barStyle);
  1211. GUILayout.EndHorizontal();
  1212. index++;
  1213. }
  1214. int afterHeight = (int)((totalCount - (startIndex + totalVisibleCount)) * size.y);
  1215. if (afterHeight > 0) {
  1216. //fill invisible gap after scroller to make proper scroller pos
  1217. GUILayout.BeginHorizontal(GUILayout.Height(afterHeight));
  1218. GUILayout.Label(" ");
  1219. GUILayout.EndHorizontal();
  1220. }
  1221. GUILayout.EndScrollView();
  1222. GUILayout.EndArea();
  1223. buttomRect.x = 0f;
  1224. buttomRect.y = Screen.height - size.y;
  1225. buttomRect.width = Screen.width;
  1226. buttomRect.height = size.y;
  1227. if (showGraph)
  1228. drawGraph();
  1229. else
  1230. drawStack();
  1231. }
  1232. float graphSize = 4f;
  1233. int startFrame = 0;
  1234. int currentFrame = 0;
  1235. Vector3 tempVector1;
  1236. Vector3 tempVector2;
  1237. Vector2 graphScrollerPos;
  1238. float maxFpsValue;
  1239. float minFpsValue;
  1240. float maxMemoryValue;
  1241. float minMemoryValue;
  1242. void drawGraph()
  1243. {
  1244. graphRect = stackRect;
  1245. graphRect.height = Screen.height * 0.25f;//- size.y ;
  1246. //startFrame = samples.Count - (int)(Screen.width / graphSize) ;
  1247. //if( startFrame < 0 ) startFrame = 0 ;
  1248. GUI.skin = graphScrollerSkin;
  1249. Vector2 drag = getDrag();
  1250. if (graphRect.Contains(new Vector2(downPos.x, Screen.height - downPos.y))) {
  1251. if (drag.x != 0) {
  1252. graphScrollerPos.x -= drag.x - oldDrag3;
  1253. graphScrollerPos.x = Mathf.Max(0, graphScrollerPos.x);
  1254. }
  1255. Vector2 p = downPos;
  1256. if (p != Vector2.zero) {
  1257. currentFrame = startFrame + (int)(p.x / graphSize);
  1258. }
  1259. }
  1260. oldDrag3 = drag.x;
  1261. GUILayout.BeginArea(graphRect, backStyle);
  1262. graphScrollerPos = GUILayout.BeginScrollView(graphScrollerPos);
  1263. startFrame = (int)(graphScrollerPos.x / graphSize);
  1264. if (graphScrollerPos.x >= (samples.Count * graphSize - Screen.width))
  1265. graphScrollerPos.x += graphSize;
  1266. GUILayout.Label(" ", GUILayout.Width(samples.Count * graphSize));
  1267. GUILayout.EndScrollView();
  1268. GUILayout.EndArea();
  1269. maxFpsValue = 0;
  1270. minFpsValue = 100000;
  1271. maxMemoryValue = 0;
  1272. minMemoryValue = 100000;
  1273. for (int i = 0; i < Screen.width / graphSize; i++) {
  1274. int index = startFrame + i;
  1275. if (index >= samples.Count)
  1276. break;
  1277. Sample s = samples[index];
  1278. if (maxFpsValue < s.fps) maxFpsValue = s.fps;
  1279. if (minFpsValue > s.fps) minFpsValue = s.fps;
  1280. if (maxMemoryValue < s.memory) maxMemoryValue = s.memory;
  1281. if (minMemoryValue > s.memory) minMemoryValue = s.memory;
  1282. }
  1283. //GUI.BeginGroup(graphRect);
  1284. if (currentFrame != -1 && currentFrame < samples.Count) {
  1285. Sample selectedSample = samples[currentFrame];
  1286. GUILayout.BeginArea(buttomRect, backStyle);
  1287. GUILayout.BeginHorizontal();
  1288. GUILayout.Box(showTimeContent, nonStyle, GUILayout.Width(size.x), GUILayout.Height(size.y));
  1289. GUILayout.Label(selectedSample.time.ToString("0.0"), nonStyle);
  1290. GUILayout.Space(size.x);
  1291. GUILayout.Box(showSceneContent, nonStyle, GUILayout.Width(size.x), GUILayout.Height(size.y));
  1292. GUILayout.Label(selectedSample.GetSceneName(), nonStyle);
  1293. GUILayout.Space(size.x);
  1294. GUILayout.Box(showMemoryContent, nonStyle, GUILayout.Width(size.x), GUILayout.Height(size.y));
  1295. GUILayout.Label(selectedSample.memory.ToString("0.000"), nonStyle);
  1296. GUILayout.Space(size.x);
  1297. GUILayout.Box(showFpsContent, nonStyle, GUILayout.Width(size.x), GUILayout.Height(size.y));
  1298. GUILayout.Label(selectedSample.fpsText, nonStyle);
  1299. GUILayout.Space(size.x);
  1300. /*GUILayout.Box( graphContent ,nonStyle, GUILayout.Width(size.x) ,GUILayout.Height(size.y));
  1301. GUILayout.Label( currentFrame.ToString() ,nonStyle );*/
  1302. GUILayout.FlexibleSpace();
  1303. GUILayout.EndHorizontal();
  1304. GUILayout.EndArea();
  1305. }
  1306. graphMaxRect = stackRect;
  1307. graphMaxRect.height = size.y;
  1308. GUILayout.BeginArea(graphMaxRect);
  1309. GUILayout.BeginHorizontal();
  1310. GUILayout.Box(showMemoryContent, nonStyle, GUILayout.Width(size.x), GUILayout.Height(size.y));
  1311. GUILayout.Label(maxMemoryValue.ToString("0.000"), nonStyle);
  1312. GUILayout.Box(showFpsContent, nonStyle, GUILayout.Width(size.x), GUILayout.Height(size.y));
  1313. GUILayout.Label(maxFpsValue.ToString("0.000"), nonStyle);
  1314. GUILayout.FlexibleSpace();
  1315. GUILayout.EndHorizontal();
  1316. GUILayout.EndArea();
  1317. graphMinRect = stackRect;
  1318. graphMinRect.y = stackRect.y + stackRect.height - size.y;
  1319. graphMinRect.height = size.y;
  1320. GUILayout.BeginArea(graphMinRect);
  1321. GUILayout.BeginHorizontal();
  1322. GUILayout.Box(showMemoryContent, nonStyle, GUILayout.Width(size.x), GUILayout.Height(size.y));
  1323. GUILayout.Label(minMemoryValue.ToString("0.000"), nonStyle);
  1324. GUILayout.Box(showFpsContent, nonStyle, GUILayout.Width(size.x), GUILayout.Height(size.y));
  1325. GUILayout.Label(minFpsValue.ToString("0.000"), nonStyle);
  1326. GUILayout.FlexibleSpace();
  1327. GUILayout.EndHorizontal();
  1328. GUILayout.EndArea();
  1329. //GUI.EndGroup();
  1330. }
  1331. void drawStack()
  1332. {
  1333. if (selectedLog != null) {
  1334. Vector2 drag = getDrag();
  1335. if (drag.y != 0 && stackRect.Contains(new Vector2(downPos.x, Screen.height - downPos.y))) {
  1336. scrollPosition2.y += drag.y - oldDrag2;
  1337. }
  1338. oldDrag2 = drag.y;
  1339. GUILayout.BeginArea(stackRect, backStyle);
  1340. scrollPosition2 = GUILayout.BeginScrollView(scrollPosition2);
  1341. Sample selectedSample = null;
  1342. try {
  1343. selectedSample = samples[selectedLog.sampleId];
  1344. }
  1345. catch (System.Exception e) {
  1346. Debug.LogException(e);
  1347. }
  1348. GUILayout.BeginHorizontal();
  1349. GUILayout.Label(selectedLog.condition, stackLabelStyle);
  1350. GUILayout.EndHorizontal();
  1351. GUILayout.Space(size.y * 0.25f);
  1352. GUILayout.BeginHorizontal();
  1353. GUILayout.Label(selectedLog.stacktrace, stackLabelStyle);
  1354. GUILayout.EndHorizontal();
  1355. GUILayout.Space(size.y);
  1356. GUILayout.EndScrollView();
  1357. GUILayout.EndArea();
  1358. GUILayout.BeginArea(buttomRect, backStyle);
  1359. GUILayout.BeginHorizontal();
  1360. GUILayout.Box(showTimeContent, nonStyle, GUILayout.Width(size.x), GUILayout.Height(size.y));
  1361. GUILayout.Label(selectedSample.time.ToString("0.000"), nonStyle);
  1362. GUILayout.Space(size.x);
  1363. GUILayout.Box(showSceneContent, nonStyle, GUILayout.Width(size.x), GUILayout.Height(size.y));
  1364. GUILayout.Label(selectedSample.GetSceneName(), nonStyle);
  1365. GUILayout.Space(size.x);
  1366. GUILayout.Box(showMemoryContent, nonStyle, GUILayout.Width(size.x), GUILayout.Height(size.y));
  1367. GUILayout.Label(selectedSample.memory.ToString("0.000"), nonStyle);
  1368. GUILayout.Space(size.x);
  1369. GUILayout.Box(showFpsContent, nonStyle, GUILayout.Width(size.x), GUILayout.Height(size.y));
  1370. GUILayout.Label(selectedSample.fpsText, nonStyle);
  1371. /*GUILayout.Space( size.x );
  1372. GUILayout.Box( graphContent ,nonStyle, GUILayout.Width(size.x) ,GUILayout.Height(size.y));
  1373. GUILayout.Label( selectedLog.sampleId.ToString() ,nonStyle );*/
  1374. GUILayout.FlexibleSpace();
  1375. GUILayout.EndHorizontal();
  1376. GUILayout.EndArea();
  1377. }
  1378. else {
  1379. GUILayout.BeginArea(stackRect, backStyle);
  1380. GUILayout.EndArea();
  1381. GUILayout.BeginArea(buttomRect, backStyle);
  1382. GUILayout.EndArea();
  1383. }
  1384. }
  1385. public void OnGUIDraw()
  1386. {
  1387. if (!show) {
  1388. return;
  1389. }
  1390. screenRect.x = 0;
  1391. screenRect.y = 0;
  1392. screenRect.width = Screen.width;
  1393. screenRect.height = Screen.height;
  1394. getDownPos();
  1395. logsRect.x = 0f;
  1396. logsRect.y = size.y * 2f;
  1397. logsRect.width = Screen.width;
  1398. logsRect.height = Screen.height * 0.75f - size.y * 2f;
  1399. stackRectTopLeft.x = 0f;
  1400. stackRect.x = 0f;
  1401. stackRectTopLeft.y = Screen.height * 0.75f;
  1402. stackRect.y = Screen.height * 0.75f;
  1403. stackRect.width = Screen.width;
  1404. stackRect.height = Screen.height * 0.25f - size.y;
  1405. detailRect.x = 0f;
  1406. detailRect.y = Screen.height - size.y * 3;
  1407. detailRect.width = Screen.width;
  1408. detailRect.height = size.y * 3;
  1409. if (currentView == ReportView.Info)
  1410. DrawInfo();
  1411. else if (currentView == ReportView.Logs) {
  1412. drawToolBar();
  1413. DrawLogs();
  1414. }
  1415. }
  1416. List<Vector2> gestureDetector = new List<Vector2>();
  1417. Vector2 gestureSum = Vector2.zero;
  1418. float gestureLength = 0;
  1419. int gestureCount = 0;
  1420. bool isGestureDone()
  1421. {
  1422. if (Application.platform == RuntimePlatform.Android ||
  1423. Application.platform == RuntimePlatform.IPhonePlayer) {
  1424. if (Input.touches.Length != 1) {
  1425. gestureDetector.Clear();
  1426. gestureCount = 0;
  1427. }
  1428. else {
  1429. if (Input.touches[0].phase == TouchPhase.Canceled || Input.touches[0].phase == TouchPhase.Ended)
  1430. gestureDetector.Clear();
  1431. else if (Input.touches[0].phase == TouchPhase.Moved) {
  1432. Vector2 p = Input.touches[0].position;
  1433. if (gestureDetector.Count == 0 || (p - gestureDetector[gestureDetector.Count - 1]).magnitude > 10)
  1434. gestureDetector.Add(p);
  1435. }
  1436. }
  1437. }
  1438. else {
  1439. if (Input.GetMouseButtonUp(0)) {
  1440. gestureDetector.Clear();
  1441. gestureCount = 0;
  1442. }
  1443. else {
  1444. if (Input.GetMouseButton(0)) {
  1445. Vector2 p = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
  1446. if (gestureDetector.Count == 0 || (p - gestureDetector[gestureDetector.Count - 1]).magnitude > 10)
  1447. gestureDetector.Add(p);
  1448. }
  1449. }
  1450. }
  1451. if (gestureDetector.Count < 10)
  1452. return false;
  1453. gestureSum = Vector2.zero;
  1454. gestureLength = 0;
  1455. Vector2 prevDelta = Vector2.zero;
  1456. for (int i = 0; i < gestureDetector.Count - 2; i++) {
  1457. Vector2 delta = gestureDetector[i + 1] - gestureDetector[i];
  1458. float deltaLength = delta.magnitude;
  1459. gestureSum += delta;
  1460. gestureLength += deltaLength;
  1461. float dot = Vector2.Dot(delta, prevDelta);
  1462. if (dot < 0f) {
  1463. gestureDetector.Clear();
  1464. gestureCount = 0;
  1465. return false;
  1466. }
  1467. prevDelta = delta;
  1468. }
  1469. int gestureBase = (Screen.width + Screen.height) / 4;
  1470. if (gestureLength > gestureBase && gestureSum.magnitude < gestureBase / 2) {
  1471. gestureDetector.Clear();
  1472. gestureCount++;
  1473. if (gestureCount >= numOfCircleToShow)
  1474. return true;
  1475. }
  1476. return false;
  1477. }
  1478. float lastClickTime = -1;
  1479. bool isDoubleClickDone()
  1480. {
  1481. if (Application.platform == RuntimePlatform.Android ||
  1482. Application.platform == RuntimePlatform.IPhonePlayer) {
  1483. if (Input.touches.Length != 1) {
  1484. lastClickTime = -1;
  1485. }
  1486. else {
  1487. if (Input.touches[0].phase == TouchPhase.Began) {
  1488. if (lastClickTime == -1)
  1489. lastClickTime = Time.realtimeSinceStartup;
  1490. else if (Time.realtimeSinceStartup - lastClickTime < 0.2f) {
  1491. lastClickTime = -1;
  1492. return true;
  1493. }
  1494. else {
  1495. lastClickTime = Time.realtimeSinceStartup;
  1496. }
  1497. }
  1498. }
  1499. }
  1500. else {
  1501. if (Input.GetMouseButtonDown(0)) {
  1502. if (lastClickTime == -1)
  1503. lastClickTime = Time.realtimeSinceStartup;
  1504. else if (Time.realtimeSinceStartup - lastClickTime < 0.2f) {
  1505. lastClickTime = -1;
  1506. return true;
  1507. }
  1508. else {
  1509. lastClickTime = Time.realtimeSinceStartup;
  1510. }
  1511. }
  1512. }
  1513. return false;
  1514. }
  1515. //calculate pos of first click on screen
  1516. Vector2 startPos;
  1517. Vector2 downPos;
  1518. Vector2 getDownPos()
  1519. {
  1520. if (Application.platform == RuntimePlatform.Android ||
  1521. Application.platform == RuntimePlatform.IPhonePlayer) {
  1522. if (Input.touches.Length == 1 && Input.touches[0].phase == TouchPhase.Began) {
  1523. downPos = Input.touches[0].position;
  1524. return downPos;
  1525. }
  1526. }
  1527. else {
  1528. if (Input.GetMouseButtonDown(0)) {
  1529. downPos.x = Input.mousePosition.x;
  1530. downPos.y = Input.mousePosition.y;
  1531. return downPos;
  1532. }
  1533. }
  1534. return Vector2.zero;
  1535. }
  1536. //calculate drag amount , this is used for scrolling
  1537. Vector2 mousePosition;
  1538. Vector2 getDrag()
  1539. {
  1540. if (Application.platform == RuntimePlatform.Android ||
  1541. Application.platform == RuntimePlatform.IPhonePlayer) {
  1542. if (Input.touches.Length != 1) {
  1543. return Vector2.zero;
  1544. }
  1545. return Input.touches[0].position - downPos;
  1546. }
  1547. else {
  1548. if (Input.GetMouseButton(0)) {
  1549. mousePosition = Input.mousePosition;
  1550. return mousePosition - downPos;
  1551. }
  1552. else {
  1553. return Vector2.zero;
  1554. }
  1555. }
  1556. }
  1557. //calculate the start index of visible log
  1558. void calculateStartIndex()
  1559. {
  1560. startIndex = (int)(scrollPosition.y / size.y);
  1561. startIndex = Mathf.Clamp(startIndex, 0, currentLog.Count);
  1562. }
  1563. // For FPS Counter
  1564. private int frames = 0;
  1565. private bool firstTime = true;
  1566. private float lastUpdate = 0f;
  1567. private const int requiredFrames = 10;
  1568. private const float updateInterval = 0.25f;
  1569. #if UNITY_CHANGE1
  1570. float lastUpdate2 = 0;
  1571. #endif
  1572. void doShow()
  1573. {
  1574. show = true;
  1575. currentView = ReportView.Logs;
  1576. gameObject.AddComponent<ReporterGUI>();
  1577. try {
  1578. gameObject.SendMessage("OnShowReporter");
  1579. }
  1580. catch (System.Exception e) {
  1581. Debug.LogException(e);
  1582. }
  1583. }
  1584. void Update()
  1585. {
  1586. fpsText = fps.ToString("0.000");
  1587. gcTotalMemory = (((float)System.GC.GetTotalMemory(false)) / 1024 / 1024);
  1588. //addSample();
  1589. #if UNITY_CHANGE3
  1590. int sceneIndex = SceneManager.GetActiveScene().buildIndex ;
  1591. if( sceneIndex != -1 && string.IsNullOrEmpty( scenes[sceneIndex] ))
  1592. scenes[ SceneManager.GetActiveScene().buildIndex ] = SceneManager.GetActiveScene().name ;
  1593. #else
  1594. int sceneIndex = Application.loadedLevel;
  1595. if (sceneIndex != -1 && string.IsNullOrEmpty(scenes[Application.loadedLevel]))
  1596. scenes[Application.loadedLevel] = Application.loadedLevelName;
  1597. #endif
  1598. calculateStartIndex();
  1599. if (!show && isGestureDone()) {
  1600. doShow();
  1601. }
  1602. if (threadedLogs.Count > 0) {
  1603. lock (threadedLogs) {
  1604. for (int i = 0; i < threadedLogs.Count; i++) {
  1605. Log l = threadedLogs[i];
  1606. AddLog(l.condition, l.stacktrace, (LogType)l.logType);
  1607. }
  1608. threadedLogs.Clear();
  1609. }
  1610. }
  1611. #if UNITY_CHANGE1
  1612. float elapsed2 = Time.realtimeSinceStartup - lastUpdate2;
  1613. if (elapsed2 > 1) {
  1614. lastUpdate2 = Time.realtimeSinceStartup;
  1615. //be sure no body else take control of log
  1616. Application.RegisterLogCallback (new Application.LogCallback (CaptureLog));
  1617. Application.RegisterLogCallbackThreaded (new Application.LogCallback (CaptureLogThread));
  1618. }
  1619. #endif
  1620. // FPS Counter
  1621. if (firstTime) {
  1622. firstTime = false;
  1623. lastUpdate = Time.realtimeSinceStartup;
  1624. frames = 0;
  1625. return;
  1626. }
  1627. frames++;
  1628. float dt = Time.realtimeSinceStartup - lastUpdate;
  1629. if (dt > updateInterval && frames > requiredFrames) {
  1630. fps = (float)frames / dt;
  1631. lastUpdate = Time.realtimeSinceStartup;
  1632. frames = 0;
  1633. }
  1634. }
  1635. void CaptureLog(string condition, string stacktrace, LogType type)
  1636. {
  1637. AddLog(condition, stacktrace, type);
  1638. }
  1639. void AddLog(string condition, string stacktrace, LogType type)
  1640. {
  1641. float memUsage = 0f;
  1642. string _condition = "";
  1643. if (cachedString.ContainsKey(condition)) {
  1644. _condition = cachedString[condition];
  1645. }
  1646. else {
  1647. _condition = condition;
  1648. cachedString.Add(_condition, _condition);
  1649. memUsage += (string.IsNullOrEmpty(_condition) ? 0 : _condition.Length * sizeof(char));
  1650. memUsage += System.IntPtr.Size;
  1651. }
  1652. string _stacktrace = "";
  1653. if (cachedString.ContainsKey(stacktrace)) {
  1654. _stacktrace = cachedString[stacktrace];
  1655. }
  1656. else {
  1657. _stacktrace = stacktrace;
  1658. cachedString.Add(_stacktrace, _stacktrace);
  1659. memUsage += (string.IsNullOrEmpty(_stacktrace) ? 0 : _stacktrace.Length * sizeof(char));
  1660. memUsage += System.IntPtr.Size;
  1661. }
  1662. bool newLogAdded = false;
  1663. addSample();
  1664. Log log = new Log() { logType = (_LogType)type, condition = _condition, stacktrace = _stacktrace, sampleId = samples.Count - 1 };
  1665. memUsage += log.GetMemoryUsage();
  1666. //memUsage += samples.Count * 13 ;
  1667. logsMemUsage += memUsage / 1024 / 1024;
  1668. if (TotalMemUsage > maxSize) {
  1669. clear();
  1670. Debug.Log("Memory Usage Reach" + maxSize + " mb So It is Cleared");
  1671. return;
  1672. }
  1673. bool isNew = false;
  1674. //string key = _condition;// + "_!_" + _stacktrace ;
  1675. if (logsDic.ContainsKey(_condition, stacktrace)) {
  1676. isNew = false;
  1677. logsDic[_condition][stacktrace].count++;
  1678. }
  1679. else {
  1680. isNew = true;
  1681. collapsedLogs.Add(log);
  1682. logsDic[_condition][stacktrace] = log;
  1683. if (type == LogType.Log)
  1684. numOfCollapsedLogs++;
  1685. else if (type == LogType.Warning)
  1686. numOfCollapsedLogsWarning++;
  1687. else
  1688. numOfCollapsedLogsError++;
  1689. }
  1690. if (type == LogType.Log)
  1691. numOfLogs++;
  1692. else if (type == LogType.Warning)
  1693. numOfLogsWarning++;
  1694. else
  1695. numOfLogsError++;
  1696. logs.Add(log);
  1697. if (!collapse || isNew) {
  1698. bool skip = false;
  1699. if (log.logType == _LogType.Log && !showLog)
  1700. skip = true;
  1701. if (log.logType == _LogType.Warning && !showWarning)
  1702. skip = true;
  1703. if (log.logType == _LogType.Error && !showError)
  1704. skip = true;
  1705. if (log.logType == _LogType.Assert && !showError)
  1706. skip = true;
  1707. if (log.logType == _LogType.Exception && !showError)
  1708. skip = true;
  1709. if (!skip) {
  1710. if (string.IsNullOrEmpty(filterText) || log.condition.ToLower().Contains(filterText.ToLower())) {
  1711. currentLog.Add(log);
  1712. newLogAdded = true;
  1713. }
  1714. }
  1715. }
  1716. if (newLogAdded) {
  1717. calculateStartIndex();
  1718. int totalCount = currentLog.Count;
  1719. int totalVisibleCount = (int)(Screen.height * 0.75f / size.y);
  1720. if (startIndex >= (totalCount - totalVisibleCount))
  1721. scrollPosition.y += size.y;
  1722. }
  1723. try {
  1724. gameObject.SendMessage("OnLog", log);
  1725. }
  1726. catch (System.Exception e) {
  1727. Debug.LogException(e);
  1728. }
  1729. }
  1730. List<Log> threadedLogs = new List<Log>();
  1731. void CaptureLogThread(string condition, string stacktrace, LogType type)
  1732. {
  1733. Log log = new Log() { condition = condition, stacktrace = stacktrace, logType = (_LogType)type };
  1734. lock (threadedLogs) {
  1735. threadedLogs.Add(log);
  1736. }
  1737. }
  1738. #if !UNITY_CHANGE3
  1739. class Scene
  1740. {
  1741. }
  1742. class LoadSceneMode
  1743. {
  1744. }
  1745. void OnLevelWasLoaded()
  1746. {
  1747. _OnLevelWasLoaded( null );
  1748. }
  1749. #endif
  1750. //new scene is loaded
  1751. void _OnLevelWasLoaded( Scene _null1 , LoadSceneMode _null2 )
  1752. {
  1753. if (clearOnNewSceneLoaded)
  1754. clear();
  1755. #if UNITY_CHANGE3
  1756. currentScene = SceneManager.GetActiveScene().name ;
  1757. Debug.Log( "Scene " + SceneManager.GetActiveScene().name + " is loaded");
  1758. #else
  1759. currentScene = Application.loadedLevelName;
  1760. Debug.Log("Scene " + Application.loadedLevelName + " is loaded");
  1761. #endif
  1762. }
  1763. //save user config
  1764. void OnApplicationQuit()
  1765. {
  1766. PlayerPrefs.SetInt("Reporter_currentView", (int)currentView);
  1767. PlayerPrefs.SetInt("Reporter_show", (show == true) ? 1 : 0);
  1768. PlayerPrefs.SetInt("Reporter_collapse", (collapse == true) ? 1 : 0);
  1769. PlayerPrefs.SetInt("Reporter_clearOnNewSceneLoaded", (clearOnNewSceneLoaded == true) ? 1 : 0);
  1770. PlayerPrefs.SetInt("Reporter_showTime", (showTime == true) ? 1 : 0);
  1771. PlayerPrefs.SetInt("Reporter_showScene", (showScene == true) ? 1 : 0);
  1772. PlayerPrefs.SetInt("Reporter_showMemory", (showMemory == true) ? 1 : 0);
  1773. PlayerPrefs.SetInt("Reporter_showFps", (showFps == true) ? 1 : 0);
  1774. PlayerPrefs.SetInt("Reporter_showGraph", (showGraph == true) ? 1 : 0);
  1775. PlayerPrefs.SetInt("Reporter_showLog", (showLog == true) ? 1 : 0);
  1776. PlayerPrefs.SetInt("Reporter_showWarning", (showWarning == true) ? 1 : 0);
  1777. PlayerPrefs.SetInt("Reporter_showError", (showError == true) ? 1 : 0);
  1778. PlayerPrefs.SetString("Reporter_filterText", filterText);
  1779. PlayerPrefs.SetFloat("Reporter_size", size.x);
  1780. PlayerPrefs.SetInt("Reporter_showClearOnNewSceneLoadedButton", (showClearOnNewSceneLoadedButton == true) ? 1 : 0);
  1781. PlayerPrefs.SetInt("Reporter_showTimeButton", (showTimeButton == true) ? 1 : 0);
  1782. PlayerPrefs.SetInt("Reporter_showSceneButton", (showSceneButton == true) ? 1 : 0);
  1783. PlayerPrefs.SetInt("Reporter_showMemButton", (showMemButton == true) ? 1 : 0);
  1784. PlayerPrefs.SetInt("Reporter_showFpsButton", (showFpsButton == true) ? 1 : 0);
  1785. PlayerPrefs.SetInt("Reporter_showSearchText", (showSearchText == true) ? 1 : 0);
  1786. PlayerPrefs.Save();
  1787. }
  1788. //read build information
  1789. IEnumerator readInfo()
  1790. {
  1791. string prefFile = "build_info";
  1792. string url = prefFile;
  1793. if (prefFile.IndexOf("://") == -1) {
  1794. string streamingAssetsPath = Application.streamingAssetsPath;
  1795. if (streamingAssetsPath == "")
  1796. streamingAssetsPath = Application.dataPath + "/StreamingAssets/";
  1797. url = System.IO.Path.Combine(streamingAssetsPath, prefFile);
  1798. }
  1799. //if (Application.platform != RuntimePlatform.OSXWebPlayer && Application.platform != RuntimePlatform.WindowsWebPlayer)
  1800. if (!url.Contains("://"))
  1801. url = "file://" + url;
  1802. // float startTime = Time.realtimeSinceStartup;
  1803. #if UNITY_CHANGE4
  1804. UnityWebRequest www = UnityWebRequest.Get(url);
  1805. yield return www.SendWebRequest();
  1806. #else
  1807. WWW www = new WWW(url);
  1808. yield return www;
  1809. #endif
  1810. if (!string.IsNullOrEmpty(www.error)) {
  1811. Debug.LogError(www.error);
  1812. }
  1813. else {
  1814. #if UNITY_CHANGE4
  1815. buildDate = www.downloadHandler.text;
  1816. #else
  1817. buildDate = www.text;
  1818. #endif
  1819. }
  1820. yield break;
  1821. }
  1822. private void SaveLogsToDevice()
  1823. {
  1824. string filePath = Application.persistentDataPath + "/logs.txt";
  1825. List<string> fileContentsList = new List<string>();
  1826. Debug.Log("Saving logs to " + filePath);
  1827. File.Delete(filePath);
  1828. for (int i = 0; i < logs.Count; i++)
  1829. {
  1830. fileContentsList.Add(logs[i].logType + "\n" + logs[i].condition + "\n" + logs[i].stacktrace);
  1831. }
  1832. File.WriteAllLines(filePath, fileContentsList.ToArray());
  1833. }
  1834. }