Reporter.cs 62 KB

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