Reporter.cs 64 KB

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