Reporter.cs 64 KB

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