Reporter.cs 64 KB

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