Reporter.cs 77 KB

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