Reporter.cs 61 KB

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