Reporter.cs 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164
  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. if (GUILayout.Button(closeContent, barStyle, GUILayout.Width(size.x * 2), GUILayout.Height(size.y * 2)))
  1002. {
  1003. show = false;
  1004. ReporterGUI gui = gameObject.GetComponent<ReporterGUI>();
  1005. DestroyImmediate(gui);
  1006. try
  1007. {
  1008. gameObject.SendMessage("OnHideReporter");
  1009. }
  1010. catch (System.Exception e)
  1011. {
  1012. Debug.LogException(e);
  1013. }
  1014. }
  1015. GUILayout.BeginHorizontal((showLog) ? buttonActiveStyle : barStyle);
  1016. if (GUILayout.Button(logContent, nonStyle, GUILayout.Width(size.x * 2), GUILayout.Height(size.y * 2))) {
  1017. showLog = !showLog;
  1018. calculateCurrentLog();
  1019. }
  1020. if (GUILayout.Button(logsText, nonStyle, GUILayout.Width(size.x * 2), GUILayout.Height(size.y * 2))) {
  1021. showLog = !showLog;
  1022. calculateCurrentLog();
  1023. }
  1024. GUILayout.EndHorizontal();
  1025. GUILayout.BeginHorizontal((showWarning) ? buttonActiveStyle : barStyle);
  1026. if (GUILayout.Button(warningContent, nonStyle, GUILayout.Width(size.x * 2), GUILayout.Height(size.y * 2))) {
  1027. showWarning = !showWarning;
  1028. calculateCurrentLog();
  1029. }
  1030. if (GUILayout.Button(logsWarningText, nonStyle, GUILayout.Width(size.x * 2), GUILayout.Height(size.y * 2))) {
  1031. showWarning = !showWarning;
  1032. calculateCurrentLog();
  1033. }
  1034. GUILayout.EndHorizontal();
  1035. GUILayout.BeginHorizontal((showError) ? buttonActiveStyle : nonStyle);
  1036. if (GUILayout.Button(errorContent, nonStyle, GUILayout.Width(size.x * 2), GUILayout.Height(size.y * 2))) {
  1037. showError = !showError;
  1038. calculateCurrentLog();
  1039. }
  1040. if (GUILayout.Button(logsErrorText, nonStyle, GUILayout.Width(size.x * 2), GUILayout.Height(size.y * 2))) {
  1041. showError = !showError;
  1042. calculateCurrentLog();
  1043. }
  1044. GUILayout.EndHorizontal();
  1045. //if (GUILayout.Button(closeContent, barStyle, GUILayout.Width(size.x * 2), GUILayout.Height(size.y * 2))) {
  1046. // show = false;
  1047. // ReporterGUI gui = gameObject.GetComponent<ReporterGUI>();
  1048. // DestroyImmediate(gui);
  1049. // try {
  1050. // gameObject.SendMessage("OnHideReporter");
  1051. // }
  1052. // catch (System.Exception e) {
  1053. // Debug.LogException(e);
  1054. // }
  1055. //}
  1056. GUILayout.EndHorizontal();
  1057. GUILayout.EndScrollView();
  1058. GUILayout.EndArea();
  1059. }
  1060. Rect tempRect;
  1061. void DrawLogs()
  1062. {
  1063. GUILayout.BeginArea(logsRect, backStyle);
  1064. GUI.skin = logScrollerSkin;
  1065. //setStartPos();
  1066. Vector2 drag = getDrag();
  1067. if (drag.y != 0 && logsRect.Contains(new Vector2(downPos.x, Screen.height - downPos.y))) {
  1068. scrollPosition.y += (drag.y - oldDrag);
  1069. }
  1070. scrollPosition = GUILayout.BeginScrollView(scrollPosition);
  1071. oldDrag = drag.y;
  1072. int totalVisibleCount = (int)(Screen.height * 0.75f / size.y);
  1073. int totalCount = currentLog.Count;
  1074. /*if( totalCount < 100 )
  1075. inGameLogsScrollerSkin.verticalScrollbarThumb.fixedHeight = 0;
  1076. else
  1077. inGameLogsScrollerSkin.verticalScrollbarThumb.fixedHeight = 64;*/
  1078. totalVisibleCount = Mathf.Min(totalVisibleCount, totalCount - startIndex);
  1079. int index = 0;
  1080. int beforeHeight = (int)(startIndex * size.y);
  1081. //selectedIndex = Mathf.Clamp( selectedIndex , -1 , totalCount -1);
  1082. if (beforeHeight > 0) {
  1083. //fill invisible gap before scroller to make proper scroller pos
  1084. GUILayout.BeginHorizontal(GUILayout.Height(beforeHeight));
  1085. GUILayout.Label("---");
  1086. GUILayout.EndHorizontal();
  1087. }
  1088. int endIndex = startIndex + totalVisibleCount;
  1089. endIndex = Mathf.Clamp(endIndex, 0, totalCount);
  1090. bool scrollerVisible = (totalVisibleCount < totalCount);
  1091. for (int i = startIndex; (startIndex + index) < endIndex; i++) {
  1092. if (i >= currentLog.Count)
  1093. break;
  1094. Log log = currentLog[i];
  1095. if (log.logType == _LogType.Log && !showLog)
  1096. continue;
  1097. if (log.logType == _LogType.Warning && !showWarning)
  1098. continue;
  1099. if (log.logType == _LogType.Error && !showError)
  1100. continue;
  1101. if (log.logType == _LogType.Assert && !showError)
  1102. continue;
  1103. if (log.logType == _LogType.Exception && !showError)
  1104. continue;
  1105. if (index >= totalVisibleCount) {
  1106. break;
  1107. }
  1108. GUIContent content = null;
  1109. if (log.logType == _LogType.Log)
  1110. content = logContent;
  1111. else if (log.logType == _LogType.Warning)
  1112. content = warningContent;
  1113. else
  1114. content = errorContent;
  1115. //content.text = log.condition ;
  1116. GUIStyle currentLogStyle = ((startIndex + index) % 2 == 0) ? evenLogStyle : oddLogStyle;
  1117. if (log == selectedLog) {
  1118. //selectedLog = log ;
  1119. currentLogStyle = selectedLogStyle;
  1120. }
  1121. else {
  1122. }
  1123. tempContent.text = log.count.ToString();
  1124. float w = 0f;
  1125. if (collapse)
  1126. w = barStyle.CalcSize(tempContent).x + 3;
  1127. countRect.x = Screen.width - w;
  1128. countRect.y = size.y * i;
  1129. if (beforeHeight > 0)
  1130. countRect.y += 8;//i will check later why
  1131. countRect.width = w;
  1132. countRect.height = size.y;
  1133. if (scrollerVisible)
  1134. countRect.x -= size.x * 2;
  1135. Sample sample = samples[log.sampleId];
  1136. fpsRect = countRect;
  1137. if (showFps) {
  1138. tempContent.text = sample.fpsText;
  1139. w = currentLogStyle.CalcSize(tempContent).x + size.x;
  1140. fpsRect.x -= w;
  1141. fpsRect.width = size.x;
  1142. fpsLabelRect = fpsRect;
  1143. fpsLabelRect.x += size.x;
  1144. fpsLabelRect.width = w - size.x;
  1145. }
  1146. memoryRect = fpsRect;
  1147. if (showMemory) {
  1148. tempContent.text = sample.memory.ToString("0.000");
  1149. w = currentLogStyle.CalcSize(tempContent).x + size.x;
  1150. memoryRect.x -= w;
  1151. memoryRect.width = size.x;
  1152. memoryLabelRect = memoryRect;
  1153. memoryLabelRect.x += size.x;
  1154. memoryLabelRect.width = w - size.x;
  1155. }
  1156. sceneRect = memoryRect;
  1157. if (showScene) {
  1158. tempContent.text = sample.GetSceneName();
  1159. w = currentLogStyle.CalcSize(tempContent).x + size.x;
  1160. sceneRect.x -= w;
  1161. sceneRect.width = size.x;
  1162. sceneLabelRect = sceneRect;
  1163. sceneLabelRect.x += size.x;
  1164. sceneLabelRect.width = w - size.x;
  1165. }
  1166. timeRect = sceneRect;
  1167. if (showTime) {
  1168. tempContent.text = sample.time.ToString("0.000");
  1169. w = currentLogStyle.CalcSize(tempContent).x + size.x;
  1170. timeRect.x -= w;
  1171. timeRect.width = size.x;
  1172. timeLabelRect = timeRect;
  1173. timeLabelRect.x += size.x;
  1174. timeLabelRect.width = w - size.x;
  1175. }
  1176. GUILayout.BeginHorizontal(currentLogStyle);
  1177. if (log == selectedLog) {
  1178. GUILayout.Box(content, nonStyle, GUILayout.Width(size.x), GUILayout.Height(size.y));
  1179. GUILayout.Label(log.condition, selectedLogFontStyle);
  1180. //GUILayout.FlexibleSpace();
  1181. if (showTime) {
  1182. GUI.Box(timeRect, showTimeContent, currentLogStyle);
  1183. GUI.Label(timeLabelRect, sample.time.ToString("0.000"), currentLogStyle);
  1184. }
  1185. if (showScene) {
  1186. GUI.Box(sceneRect, showSceneContent, currentLogStyle);
  1187. GUI.Label(sceneLabelRect, sample.GetSceneName(), currentLogStyle);
  1188. }
  1189. if (showMemory) {
  1190. GUI.Box(memoryRect, showMemoryContent, currentLogStyle);
  1191. GUI.Label(memoryLabelRect, sample.memory.ToString("0.000") + " mb", currentLogStyle);
  1192. }
  1193. if (showFps) {
  1194. GUI.Box(fpsRect, showFpsContent, currentLogStyle);
  1195. GUI.Label(fpsLabelRect, sample.fpsText, currentLogStyle);
  1196. }
  1197. }
  1198. else {
  1199. if (GUILayout.Button(content, nonStyle, GUILayout.Width(size.x), GUILayout.Height(size.y))) {
  1200. //selectedIndex = startIndex + index ;
  1201. selectedLog = log;
  1202. }
  1203. if (GUILayout.Button(log.condition, logButtonStyle)) {
  1204. //selectedIndex = startIndex + index ;
  1205. selectedLog = log;
  1206. }
  1207. //GUILayout.FlexibleSpace();
  1208. if (showTime) {
  1209. GUI.Box(timeRect, showTimeContent, currentLogStyle);
  1210. GUI.Label(timeLabelRect, sample.time.ToString("0.000"), currentLogStyle);
  1211. }
  1212. if (showScene) {
  1213. GUI.Box(sceneRect, showSceneContent, currentLogStyle);
  1214. GUI.Label(sceneLabelRect, sample.GetSceneName(), currentLogStyle);
  1215. }
  1216. if (showMemory) {
  1217. GUI.Box(memoryRect, showMemoryContent, currentLogStyle);
  1218. GUI.Label(memoryLabelRect, sample.memory.ToString("0.000") + " mb", currentLogStyle);
  1219. }
  1220. if (showFps) {
  1221. GUI.Box(fpsRect, showFpsContent, currentLogStyle);
  1222. GUI.Label(fpsLabelRect, sample.fpsText, currentLogStyle);
  1223. }
  1224. }
  1225. if (collapse)
  1226. GUI.Label(countRect, log.count.ToString(), barStyle);
  1227. GUILayout.EndHorizontal();
  1228. index++;
  1229. }
  1230. int afterHeight = (int)((totalCount - (startIndex + totalVisibleCount)) * size.y);
  1231. if (afterHeight > 0) {
  1232. //fill invisible gap after scroller to make proper scroller pos
  1233. GUILayout.BeginHorizontal(GUILayout.Height(afterHeight));
  1234. GUILayout.Label(" ");
  1235. GUILayout.EndHorizontal();
  1236. }
  1237. GUILayout.EndScrollView();
  1238. GUILayout.EndArea();
  1239. buttomRect.x = 0f;
  1240. buttomRect.y = Screen.height - size.y;
  1241. buttomRect.width = Screen.width;
  1242. buttomRect.height = size.y;
  1243. if (showGraph)
  1244. drawGraph();
  1245. else
  1246. drawStack();
  1247. }
  1248. float graphSize = 4f;
  1249. int startFrame = 0;
  1250. int currentFrame = 0;
  1251. Vector3 tempVector1;
  1252. Vector3 tempVector2;
  1253. Vector2 graphScrollerPos;
  1254. float maxFpsValue;
  1255. float minFpsValue;
  1256. float maxMemoryValue;
  1257. float minMemoryValue;
  1258. void drawGraph()
  1259. {
  1260. graphRect = stackRect;
  1261. graphRect.height = Screen.height * 0.25f;//- size.y ;
  1262. //startFrame = samples.Count - (int)(Screen.width / graphSize) ;
  1263. //if( startFrame < 0 ) startFrame = 0 ;
  1264. GUI.skin = graphScrollerSkin;
  1265. Vector2 drag = getDrag();
  1266. if (graphRect.Contains(new Vector2(downPos.x, Screen.height - downPos.y))) {
  1267. if (drag.x != 0) {
  1268. graphScrollerPos.x -= drag.x - oldDrag3;
  1269. graphScrollerPos.x = Mathf.Max(0, graphScrollerPos.x);
  1270. }
  1271. Vector2 p = downPos;
  1272. if (p != Vector2.zero) {
  1273. currentFrame = startFrame + (int)(p.x / graphSize);
  1274. }
  1275. }
  1276. oldDrag3 = drag.x;
  1277. GUILayout.BeginArea(graphRect, backStyle);
  1278. graphScrollerPos = GUILayout.BeginScrollView(graphScrollerPos);
  1279. startFrame = (int)(graphScrollerPos.x / graphSize);
  1280. if (graphScrollerPos.x >= (samples.Count * graphSize - Screen.width))
  1281. graphScrollerPos.x += graphSize;
  1282. GUILayout.Label(" ", GUILayout.Width(samples.Count * graphSize));
  1283. GUILayout.EndScrollView();
  1284. GUILayout.EndArea();
  1285. maxFpsValue = 0;
  1286. minFpsValue = 100000;
  1287. maxMemoryValue = 0;
  1288. minMemoryValue = 100000;
  1289. for (int i = 0; i < Screen.width / graphSize; i++) {
  1290. int index = startFrame + i;
  1291. if (index >= samples.Count)
  1292. break;
  1293. Sample s = samples[index];
  1294. if (maxFpsValue < s.fps) maxFpsValue = s.fps;
  1295. if (minFpsValue > s.fps) minFpsValue = s.fps;
  1296. if (maxMemoryValue < s.memory) maxMemoryValue = s.memory;
  1297. if (minMemoryValue > s.memory) minMemoryValue = s.memory;
  1298. }
  1299. //GUI.BeginGroup(graphRect);
  1300. if (currentFrame != -1 && currentFrame < samples.Count) {
  1301. Sample selectedSample = samples[currentFrame];
  1302. GUILayout.BeginArea(buttomRect, backStyle);
  1303. GUILayout.BeginHorizontal();
  1304. GUILayout.Box(showTimeContent, nonStyle, GUILayout.Width(size.x), GUILayout.Height(size.y));
  1305. GUILayout.Label(selectedSample.time.ToString("0.0"), nonStyle);
  1306. GUILayout.Space(size.x);
  1307. GUILayout.Box(showSceneContent, nonStyle, GUILayout.Width(size.x), GUILayout.Height(size.y));
  1308. GUILayout.Label(selectedSample.GetSceneName(), nonStyle);
  1309. GUILayout.Space(size.x);
  1310. GUILayout.Box(showMemoryContent, nonStyle, GUILayout.Width(size.x), GUILayout.Height(size.y));
  1311. GUILayout.Label(selectedSample.memory.ToString("0.000"), nonStyle);
  1312. GUILayout.Space(size.x);
  1313. GUILayout.Box(showFpsContent, nonStyle, GUILayout.Width(size.x), GUILayout.Height(size.y));
  1314. GUILayout.Label(selectedSample.fpsText, nonStyle);
  1315. GUILayout.Space(size.x);
  1316. /*GUILayout.Box( graphContent ,nonStyle, GUILayout.Width(size.x) ,GUILayout.Height(size.y));
  1317. GUILayout.Label( currentFrame.ToString() ,nonStyle );*/
  1318. GUILayout.FlexibleSpace();
  1319. GUILayout.EndHorizontal();
  1320. GUILayout.EndArea();
  1321. }
  1322. graphMaxRect = stackRect;
  1323. graphMaxRect.height = size.y;
  1324. GUILayout.BeginArea(graphMaxRect);
  1325. GUILayout.BeginHorizontal();
  1326. GUILayout.Box(showMemoryContent, nonStyle, GUILayout.Width(size.x), GUILayout.Height(size.y));
  1327. GUILayout.Label(maxMemoryValue.ToString("0.000"), nonStyle);
  1328. GUILayout.Box(showFpsContent, nonStyle, GUILayout.Width(size.x), GUILayout.Height(size.y));
  1329. GUILayout.Label(maxFpsValue.ToString("0.000"), nonStyle);
  1330. GUILayout.FlexibleSpace();
  1331. GUILayout.EndHorizontal();
  1332. GUILayout.EndArea();
  1333. graphMinRect = stackRect;
  1334. graphMinRect.y = stackRect.y + stackRect.height - size.y;
  1335. graphMinRect.height = size.y;
  1336. GUILayout.BeginArea(graphMinRect);
  1337. GUILayout.BeginHorizontal();
  1338. GUILayout.Box(showMemoryContent, nonStyle, GUILayout.Width(size.x), GUILayout.Height(size.y));
  1339. GUILayout.Label(minMemoryValue.ToString("0.000"), nonStyle);
  1340. GUILayout.Box(showFpsContent, nonStyle, GUILayout.Width(size.x), GUILayout.Height(size.y));
  1341. GUILayout.Label(minFpsValue.ToString("0.000"), nonStyle);
  1342. GUILayout.FlexibleSpace();
  1343. GUILayout.EndHorizontal();
  1344. GUILayout.EndArea();
  1345. //GUI.EndGroup();
  1346. }
  1347. void drawStack()
  1348. {
  1349. if (selectedLog != null) {
  1350. Vector2 drag = getDrag();
  1351. if (drag.y != 0 && stackRect.Contains(new Vector2(downPos.x, Screen.height - downPos.y))) {
  1352. scrollPosition2.y += drag.y - oldDrag2;
  1353. }
  1354. oldDrag2 = drag.y;
  1355. GUILayout.BeginArea(stackRect, backStyle);
  1356. scrollPosition2 = GUILayout.BeginScrollView(scrollPosition2);
  1357. Sample selectedSample = null;
  1358. try {
  1359. selectedSample = samples[selectedLog.sampleId];
  1360. }
  1361. catch (System.Exception e) {
  1362. Debug.LogException(e);
  1363. }
  1364. GUILayout.BeginHorizontal();
  1365. GUILayout.Label(selectedLog.condition, stackLabelStyle);
  1366. GUILayout.EndHorizontal();
  1367. GUILayout.Space(size.y * 0.25f);
  1368. GUILayout.BeginHorizontal();
  1369. GUILayout.Label(selectedLog.stacktrace, stackLabelStyle);
  1370. GUILayout.EndHorizontal();
  1371. GUILayout.Space(size.y);
  1372. GUILayout.EndScrollView();
  1373. GUILayout.EndArea();
  1374. GUILayout.BeginArea(buttomRect, backStyle);
  1375. GUILayout.BeginHorizontal();
  1376. GUILayout.Box(showTimeContent, nonStyle, GUILayout.Width(size.x), GUILayout.Height(size.y));
  1377. GUILayout.Label(selectedSample.time.ToString("0.000"), nonStyle);
  1378. GUILayout.Space(size.x);
  1379. GUILayout.Box(showSceneContent, nonStyle, GUILayout.Width(size.x), GUILayout.Height(size.y));
  1380. GUILayout.Label(selectedSample.GetSceneName(), nonStyle);
  1381. GUILayout.Space(size.x);
  1382. GUILayout.Box(showMemoryContent, nonStyle, GUILayout.Width(size.x), GUILayout.Height(size.y));
  1383. GUILayout.Label(selectedSample.memory.ToString("0.000"), nonStyle);
  1384. GUILayout.Space(size.x);
  1385. GUILayout.Box(showFpsContent, nonStyle, GUILayout.Width(size.x), GUILayout.Height(size.y));
  1386. GUILayout.Label(selectedSample.fpsText, nonStyle);
  1387. /*GUILayout.Space( size.x );
  1388. GUILayout.Box( graphContent ,nonStyle, GUILayout.Width(size.x) ,GUILayout.Height(size.y));
  1389. GUILayout.Label( selectedLog.sampleId.ToString() ,nonStyle );*/
  1390. GUILayout.FlexibleSpace();
  1391. GUILayout.EndHorizontal();
  1392. GUILayout.EndArea();
  1393. }
  1394. else {
  1395. GUILayout.BeginArea(stackRect, backStyle);
  1396. GUILayout.EndArea();
  1397. GUILayout.BeginArea(buttomRect, backStyle);
  1398. GUILayout.EndArea();
  1399. }
  1400. }
  1401. public void OnGUIDraw()
  1402. {
  1403. if (!show) {
  1404. return;
  1405. }
  1406. screenRect.x = 0;
  1407. screenRect.y = 0;
  1408. screenRect.width = Screen.width;
  1409. screenRect.height = Screen.height;
  1410. getDownPos();
  1411. logsRect.x = 0f;
  1412. logsRect.y = size.y * 2f;
  1413. logsRect.width = Screen.width;
  1414. logsRect.height = Screen.height * 0.75f - size.y * 2f;
  1415. stackRectTopLeft.x = 0f;
  1416. stackRect.x = 0f;
  1417. stackRectTopLeft.y = Screen.height * 0.75f;
  1418. stackRect.y = Screen.height * 0.75f;
  1419. stackRect.width = Screen.width;
  1420. stackRect.height = Screen.height * 0.25f - size.y;
  1421. detailRect.x = 0f;
  1422. detailRect.y = Screen.height - size.y * 3;
  1423. detailRect.width = Screen.width;
  1424. detailRect.height = size.y * 3;
  1425. if (currentView == ReportView.Info)
  1426. DrawInfo();
  1427. else if (currentView == ReportView.Logs) {
  1428. drawToolBar();
  1429. DrawLogs();
  1430. }
  1431. }
  1432. List<Vector2> gestureDetector = new List<Vector2>();
  1433. Vector2 gestureSum = Vector2.zero;
  1434. float gestureLength = 0;
  1435. int gestureCount = 0;
  1436. bool isGestureDone()
  1437. {
  1438. if (Application.platform == RuntimePlatform.Android ||
  1439. Application.platform == RuntimePlatform.IPhonePlayer) {
  1440. if (Input.touches.Length != 1) {
  1441. gestureDetector.Clear();
  1442. gestureCount = 0;
  1443. }
  1444. else {
  1445. if (Input.touches[0].phase == TouchPhase.Canceled || Input.touches[0].phase == TouchPhase.Ended)
  1446. gestureDetector.Clear();
  1447. else if (Input.touches[0].phase == TouchPhase.Moved) {
  1448. Vector2 p = Input.touches[0].position;
  1449. if (gestureDetector.Count == 0 || (p - gestureDetector[gestureDetector.Count - 1]).magnitude > 10)
  1450. gestureDetector.Add(p);
  1451. }
  1452. }
  1453. }
  1454. else {
  1455. if (Input.GetMouseButtonUp(0)) {
  1456. gestureDetector.Clear();
  1457. gestureCount = 0;
  1458. }
  1459. else {
  1460. if (Input.GetMouseButton(0)) {
  1461. Vector2 p = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
  1462. if (gestureDetector.Count == 0 || (p - gestureDetector[gestureDetector.Count - 1]).magnitude > 10)
  1463. gestureDetector.Add(p);
  1464. }
  1465. }
  1466. }
  1467. if (gestureDetector.Count < 10)
  1468. return false;
  1469. gestureSum = Vector2.zero;
  1470. gestureLength = 0;
  1471. Vector2 prevDelta = Vector2.zero;
  1472. for (int i = 0; i < gestureDetector.Count - 2; i++) {
  1473. Vector2 delta = gestureDetector[i + 1] - gestureDetector[i];
  1474. float deltaLength = delta.magnitude;
  1475. gestureSum += delta;
  1476. gestureLength += deltaLength;
  1477. float dot = Vector2.Dot(delta, prevDelta);
  1478. if (dot < 0f) {
  1479. gestureDetector.Clear();
  1480. gestureCount = 0;
  1481. return false;
  1482. }
  1483. prevDelta = delta;
  1484. }
  1485. int gestureBase = (Screen.width + Screen.height) / 4;
  1486. if (gestureLength > gestureBase && gestureSum.magnitude < gestureBase / 2) {
  1487. gestureDetector.Clear();
  1488. gestureCount++;
  1489. if (gestureCount >= numOfCircleToShow)
  1490. return true;
  1491. }
  1492. return false;
  1493. }
  1494. float lastClickTime = -1;
  1495. bool isDoubleClickDone()
  1496. {
  1497. if (Application.platform == RuntimePlatform.Android ||
  1498. Application.platform == RuntimePlatform.IPhonePlayer) {
  1499. if (Input.touches.Length != 1) {
  1500. lastClickTime = -1;
  1501. }
  1502. else {
  1503. if (Input.touches[0].phase == TouchPhase.Began) {
  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. }
  1516. else {
  1517. if (Input.GetMouseButtonDown(0)) {
  1518. if (lastClickTime == -1)
  1519. lastClickTime = Time.realtimeSinceStartup;
  1520. else if (Time.realtimeSinceStartup - lastClickTime < 0.2f) {
  1521. lastClickTime = -1;
  1522. return true;
  1523. }
  1524. else {
  1525. lastClickTime = Time.realtimeSinceStartup;
  1526. }
  1527. }
  1528. }
  1529. return false;
  1530. }
  1531. //calculate pos of first click on screen
  1532. Vector2 startPos;
  1533. Vector2 downPos;
  1534. Vector2 getDownPos()
  1535. {
  1536. if (Application.platform == RuntimePlatform.Android ||
  1537. Application.platform == RuntimePlatform.IPhonePlayer) {
  1538. if (Input.touches.Length == 1 && Input.touches[0].phase == TouchPhase.Began) {
  1539. downPos = Input.touches[0].position;
  1540. return downPos;
  1541. }
  1542. }
  1543. else {
  1544. if (Input.GetMouseButtonDown(0)) {
  1545. downPos.x = Input.mousePosition.x;
  1546. downPos.y = Input.mousePosition.y;
  1547. return downPos;
  1548. }
  1549. }
  1550. return Vector2.zero;
  1551. }
  1552. //calculate drag amount , this is used for scrolling
  1553. Vector2 mousePosition;
  1554. Vector2 getDrag()
  1555. {
  1556. if (Application.platform == RuntimePlatform.Android ||
  1557. Application.platform == RuntimePlatform.IPhonePlayer) {
  1558. if (Input.touches.Length != 1) {
  1559. return Vector2.zero;
  1560. }
  1561. return Input.touches[0].position - downPos;
  1562. }
  1563. else {
  1564. if (Input.GetMouseButton(0)) {
  1565. mousePosition = Input.mousePosition;
  1566. return mousePosition - downPos;
  1567. }
  1568. else {
  1569. return Vector2.zero;
  1570. }
  1571. }
  1572. }
  1573. //calculate the start index of visible log
  1574. void calculateStartIndex()
  1575. {
  1576. startIndex = (int)(scrollPosition.y / size.y);
  1577. startIndex = Mathf.Clamp(startIndex, 0, currentLog.Count);
  1578. }
  1579. // For FPS Counter
  1580. private int frames = 0;
  1581. private bool firstTime = true;
  1582. private float lastUpdate = 0f;
  1583. private const int requiredFrames = 10;
  1584. private const float updateInterval = 0.25f;
  1585. #if UNITY_CHANGE1
  1586. float lastUpdate2 = 0;
  1587. #endif
  1588. void doShow()
  1589. {
  1590. show = true;
  1591. currentView = ReportView.Logs;
  1592. gameObject.AddComponent<ReporterGUI>();
  1593. try {
  1594. gameObject.SendMessage("OnShowReporter");
  1595. }
  1596. catch (System.Exception e) {
  1597. Debug.LogException(e);
  1598. }
  1599. }
  1600. void Update()
  1601. {
  1602. fpsText = fps.ToString("0.000");
  1603. gcTotalMemory = (((float)System.GC.GetTotalMemory(false)) / 1024 / 1024);
  1604. //addSample();
  1605. #if UNITY_CHANGE3
  1606. int sceneIndex = SceneManager.GetActiveScene().buildIndex ;
  1607. if( sceneIndex != -1 && string.IsNullOrEmpty( scenes[sceneIndex] ))
  1608. scenes[ SceneManager.GetActiveScene().buildIndex ] = SceneManager.GetActiveScene().name ;
  1609. #else
  1610. int sceneIndex = Application.loadedLevel;
  1611. if (sceneIndex != -1 && string.IsNullOrEmpty(scenes[Application.loadedLevel]))
  1612. scenes[Application.loadedLevel] = Application.loadedLevelName;
  1613. #endif
  1614. calculateStartIndex();
  1615. if (!show && isGestureDone()) {
  1616. doShow();
  1617. }
  1618. if (threadedLogs.Count > 0) {
  1619. lock (threadedLogs) {
  1620. for (int i = 0; i < threadedLogs.Count; i++) {
  1621. Log l = threadedLogs[i];
  1622. AddLog(l.condition, l.stacktrace, (LogType)l.logType);
  1623. }
  1624. threadedLogs.Clear();
  1625. }
  1626. }
  1627. #if UNITY_CHANGE1
  1628. float elapsed2 = Time.realtimeSinceStartup - lastUpdate2;
  1629. if (elapsed2 > 1) {
  1630. lastUpdate2 = Time.realtimeSinceStartup;
  1631. //be sure no body else take control of log
  1632. Application.RegisterLogCallback (new Application.LogCallback (CaptureLog));
  1633. Application.RegisterLogCallbackThreaded (new Application.LogCallback (CaptureLogThread));
  1634. }
  1635. #endif
  1636. // FPS Counter
  1637. if (firstTime) {
  1638. firstTime = false;
  1639. lastUpdate = Time.realtimeSinceStartup;
  1640. frames = 0;
  1641. return;
  1642. }
  1643. frames++;
  1644. float dt = Time.realtimeSinceStartup - lastUpdate;
  1645. if (dt > updateInterval && frames > requiredFrames) {
  1646. fps = (float)frames / dt;
  1647. lastUpdate = Time.realtimeSinceStartup;
  1648. frames = 0;
  1649. }
  1650. }
  1651. void CaptureLog(string condition, string stacktrace, LogType type)
  1652. {
  1653. AddLog(condition, stacktrace, type);
  1654. }
  1655. void AddLog(string condition, string stacktrace, LogType type)
  1656. {
  1657. float memUsage = 0f;
  1658. string _condition = "";
  1659. if (cachedString.ContainsKey(condition)) {
  1660. _condition = cachedString[condition];
  1661. }
  1662. else {
  1663. _condition = condition;
  1664. cachedString.Add(_condition, _condition);
  1665. memUsage += (string.IsNullOrEmpty(_condition) ? 0 : _condition.Length * sizeof(char));
  1666. memUsage += System.IntPtr.Size;
  1667. }
  1668. string _stacktrace = "";
  1669. if (cachedString.ContainsKey(stacktrace)) {
  1670. _stacktrace = cachedString[stacktrace];
  1671. }
  1672. else {
  1673. _stacktrace = stacktrace;
  1674. cachedString.Add(_stacktrace, _stacktrace);
  1675. memUsage += (string.IsNullOrEmpty(_stacktrace) ? 0 : _stacktrace.Length * sizeof(char));
  1676. memUsage += System.IntPtr.Size;
  1677. }
  1678. bool newLogAdded = false;
  1679. addSample();
  1680. Log log = new Log() { logType = (_LogType)type, condition = _condition, stacktrace = _stacktrace, sampleId = samples.Count - 1 };
  1681. memUsage += log.GetMemoryUsage();
  1682. //memUsage += samples.Count * 13 ;
  1683. logsMemUsage += memUsage / 1024 / 1024;
  1684. if (TotalMemUsage > maxSize) {
  1685. clear();
  1686. Debug.Log("Memory Usage Reach" + maxSize + " mb So It is Cleared");
  1687. return;
  1688. }
  1689. bool isNew = false;
  1690. //string key = _condition;// + "_!_" + _stacktrace ;
  1691. if (logsDic.ContainsKey(_condition, stacktrace)) {
  1692. isNew = false;
  1693. logsDic[_condition][stacktrace].count++;
  1694. }
  1695. else {
  1696. isNew = true;
  1697. collapsedLogs.Add(log);
  1698. logsDic[_condition][stacktrace] = log;
  1699. if (type == LogType.Log)
  1700. numOfCollapsedLogs++;
  1701. else if (type == LogType.Warning)
  1702. numOfCollapsedLogsWarning++;
  1703. else
  1704. numOfCollapsedLogsError++;
  1705. }
  1706. if (type == LogType.Log)
  1707. numOfLogs++;
  1708. else if (type == LogType.Warning)
  1709. numOfLogsWarning++;
  1710. else
  1711. numOfLogsError++;
  1712. logs.Add(log);
  1713. if (!collapse || isNew) {
  1714. bool skip = false;
  1715. if (log.logType == _LogType.Log && !showLog)
  1716. skip = true;
  1717. if (log.logType == _LogType.Warning && !showWarning)
  1718. skip = true;
  1719. if (log.logType == _LogType.Error && !showError)
  1720. skip = true;
  1721. if (log.logType == _LogType.Assert && !showError)
  1722. skip = true;
  1723. if (log.logType == _LogType.Exception && !showError)
  1724. skip = true;
  1725. if (!skip) {
  1726. if (string.IsNullOrEmpty(filterText) || log.condition.ToLower().Contains(filterText.ToLower())) {
  1727. currentLog.Add(log);
  1728. newLogAdded = true;
  1729. }
  1730. }
  1731. }
  1732. if (newLogAdded) {
  1733. calculateStartIndex();
  1734. int totalCount = currentLog.Count;
  1735. int totalVisibleCount = (int)(Screen.height * 0.75f / size.y);
  1736. if (startIndex >= (totalCount - totalVisibleCount))
  1737. scrollPosition.y += size.y;
  1738. }
  1739. try {
  1740. gameObject.SendMessage("OnLog", log);
  1741. }
  1742. catch (System.Exception e) {
  1743. Debug.LogException(e);
  1744. }
  1745. }
  1746. List<Log> threadedLogs = new List<Log>();
  1747. void CaptureLogThread(string condition, string stacktrace, LogType type)
  1748. {
  1749. Log log = new Log() { condition = condition, stacktrace = stacktrace, logType = (_LogType)type };
  1750. lock (threadedLogs) {
  1751. threadedLogs.Add(log);
  1752. }
  1753. }
  1754. #if !UNITY_CHANGE3
  1755. class Scene
  1756. {
  1757. }
  1758. class LoadSceneMode
  1759. {
  1760. }
  1761. void OnLevelWasLoaded()
  1762. {
  1763. _OnLevelWasLoaded( null );
  1764. }
  1765. #endif
  1766. //new scene is loaded
  1767. void _OnLevelWasLoaded( Scene _null1 , LoadSceneMode _null2 )
  1768. {
  1769. if (clearOnNewSceneLoaded)
  1770. clear();
  1771. #if UNITY_CHANGE3
  1772. currentScene = SceneManager.GetActiveScene().name ;
  1773. // Debug.Log( "Scene " + SceneManager.GetActiveScene().name + " is loaded");
  1774. #else
  1775. currentScene = Application.loadedLevelName;
  1776. // Debug.Log("Scene " + Application.loadedLevelName + " is loaded");
  1777. #endif
  1778. }
  1779. //save user config
  1780. void OnApplicationQuit()
  1781. {
  1782. PlayerPrefs.SetInt("Reporter_currentView", (int)currentView);
  1783. PlayerPrefs.SetInt("Reporter_show", (show == true) ? 1 : 0);
  1784. PlayerPrefs.SetInt("Reporter_collapse", (collapse == true) ? 1 : 0);
  1785. PlayerPrefs.SetInt("Reporter_clearOnNewSceneLoaded", (clearOnNewSceneLoaded == true) ? 1 : 0);
  1786. PlayerPrefs.SetInt("Reporter_showTime", (showTime == true) ? 1 : 0);
  1787. PlayerPrefs.SetInt("Reporter_showScene", (showScene == true) ? 1 : 0);
  1788. PlayerPrefs.SetInt("Reporter_showMemory", (showMemory == true) ? 1 : 0);
  1789. PlayerPrefs.SetInt("Reporter_showFps", (showFps == true) ? 1 : 0);
  1790. PlayerPrefs.SetInt("Reporter_showGraph", (showGraph == true) ? 1 : 0);
  1791. PlayerPrefs.SetInt("Reporter_showLog", (showLog == true) ? 1 : 0);
  1792. PlayerPrefs.SetInt("Reporter_showWarning", (showWarning == true) ? 1 : 0);
  1793. PlayerPrefs.SetInt("Reporter_showError", (showError == true) ? 1 : 0);
  1794. PlayerPrefs.SetString("Reporter_filterText", filterText);
  1795. PlayerPrefs.SetFloat("Reporter_size", size.x);
  1796. PlayerPrefs.SetInt("Reporter_showClearOnNewSceneLoadedButton", (showClearOnNewSceneLoadedButton == true) ? 1 : 0);
  1797. PlayerPrefs.SetInt("Reporter_showTimeButton", (showTimeButton == true) ? 1 : 0);
  1798. PlayerPrefs.SetInt("Reporter_showSceneButton", (showSceneButton == true) ? 1 : 0);
  1799. PlayerPrefs.SetInt("Reporter_showMemButton", (showMemButton == true) ? 1 : 0);
  1800. PlayerPrefs.SetInt("Reporter_showFpsButton", (showFpsButton == true) ? 1 : 0);
  1801. PlayerPrefs.SetInt("Reporter_showSearchText", (showSearchText == true) ? 1 : 0);
  1802. PlayerPrefs.Save();
  1803. }
  1804. //read build information
  1805. IEnumerator readInfo()
  1806. {
  1807. // string prefFile = "build_info";
  1808. // string url = prefFile;
  1809. // if (prefFile.IndexOf("://") == -1) {
  1810. // string streamingAssetsPath = Application.streamingAssetsPath;
  1811. // if (streamingAssetsPath == "")
  1812. // streamingAssetsPath = Application.dataPath + "/StreamingAssets/";
  1813. // url = System.IO.Path.Combine(streamingAssetsPath, prefFile);
  1814. // }
  1815. // //if (Application.platform != RuntimePlatform.OSXWebPlayer && Application.platform != RuntimePlatform.WindowsWebPlayer)
  1816. // if (!url.Contains("://"))
  1817. // url = "file://" + url;
  1818. // // float startTime = Time.realtimeSinceStartup;
  1819. // #if UNITY_CHANGE4
  1820. // UnityWebRequest www = UnityWebRequest.Get(url);
  1821. // yield return www.SendWebRequest();
  1822. // #else
  1823. // WWW www = new WWW(url);
  1824. // yield return www;
  1825. // #endif
  1826. // if (!string.IsNullOrEmpty(www.error)) {
  1827. // Debug.LogError(www.error);
  1828. // }
  1829. // else {
  1830. // #if UNITY_CHANGE4
  1831. // buildDate = www.downloadHandler.text;
  1832. // #else
  1833. // buildDate = www.text;
  1834. // #endif
  1835. // }
  1836. // yield break;
  1837. yield return null;
  1838. buildDate = "";
  1839. }
  1840. private void SaveLogsToDevice()
  1841. {
  1842. string filePath = Application.persistentDataPath + "/logs.txt";
  1843. List<string> fileContentsList = new List<string>();
  1844. Debug.Log("Saving logs to " + filePath);
  1845. File.Delete(filePath);
  1846. for (int i = 0; i < logs.Count; i++)
  1847. {
  1848. fileContentsList.Add(logs[i].logType + "\n" + logs[i].condition + "\n" + logs[i].stacktrace);
  1849. }
  1850. File.WriteAllLines(filePath, fileContentsList.ToArray());
  1851. }
  1852. }