Reporter.cs 62 KB

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