Reporter.cs 65 KB

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