LuaDeepProfilerSetting.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. /*
  2. #########
  3. ############
  4. #############
  5. ## ###########
  6. ### ###### #####
  7. ### ####### ####
  8. ### ########## ####
  9. #### ########### ####
  10. #### ########### #####
  11. ##### ### ######## #####
  12. ##### ### ######## ######
  13. ###### ### ########### ######
  14. ###### #### ############## ######
  15. ####### ##################### ######
  16. ####### ###################### ######
  17. ####### ###### ################# ######
  18. ####### ###### ###### ######### ######
  19. ####### ## ###### ###### ######
  20. ####### ###### ##### #####
  21. ###### ##### ##### ####
  22. ##### #### ##### ###
  23. ##### ### ### #
  24. ### ### ###
  25. ## ### ###
  26. __________#_______####_______####______________
  27. 我们的未来没有BUG
  28. * ==============================================================================
  29. * Filename: LuaDeepProfilerSetting.cs
  30. * Created: 2018/7/13 14:29:22
  31. * Author: エル・プサイ・コングリィ
  32. * Purpose:
  33. * ==============================================================================
  34. */
  35. #if UNITY_EDITOR || USE_LUA_PROFILER
  36. namespace MikuLuaProfiler
  37. {
  38. using System.Diagnostics;
  39. using System.IO;
  40. using System.Runtime.InteropServices;
  41. using System.Text;
  42. using UnityEngine;
  43. public class LuaDeepProfilerSetting
  44. {
  45. public static LuaDeepProfilerSetting MakeInstance()
  46. {
  47. instance = LuaDeepProfilerSetting.Load();
  48. return instance;
  49. }
  50. public static LuaDeepProfilerSetting Instance
  51. {
  52. get
  53. {
  54. #if UNITY_EDITOR
  55. if (instance == null)
  56. {
  57. instance = MakeInstance();
  58. }
  59. #endif
  60. return instance;
  61. }
  62. }
  63. public bool isDeepMonoProfiler
  64. {
  65. get
  66. {
  67. #if UNITY_EDITOR
  68. return LuaDeepProfilerAssetSetting.Instance.isDeepMonoProfiler;
  69. #else
  70. return this.m_isDeepMonoProfiler;
  71. #endif
  72. }
  73. set
  74. {
  75. #if UNITY_EDITOR
  76. LuaDeepProfilerAssetSetting.Instance.isDeepMonoProfiler = value;
  77. #endif
  78. if (this.m_isDeepMonoProfiler != value)
  79. {
  80. this.m_isDeepMonoProfiler = value;
  81. this.Save();
  82. }
  83. }
  84. }
  85. public bool isDeepLuaProfiler
  86. {
  87. get
  88. {
  89. #if UNITY_EDITOR
  90. return LuaDeepProfilerAssetSetting.Instance.isDeepLuaProfiler;
  91. #else
  92. return this.m_isDeepLuaProfiler;
  93. #endif
  94. }
  95. set
  96. {
  97. #if UNITY_EDITOR
  98. LuaDeepProfilerAssetSetting.Instance.isDeepLuaProfiler = value;
  99. #endif
  100. if (this.m_isDeepLuaProfiler != value)
  101. {
  102. this.m_isDeepLuaProfiler = value;
  103. this.Save();
  104. }
  105. }
  106. }
  107. public bool isCleanMode
  108. {
  109. get
  110. {
  111. return m_isCleanMode;
  112. }
  113. set
  114. {
  115. if (this.m_isCleanMode != value)
  116. {
  117. this.m_isCleanMode = value;
  118. this.Save();
  119. }
  120. }
  121. }
  122. public int captureLuaGC
  123. {
  124. get
  125. {
  126. return this.m_captureLuaGC;
  127. }
  128. set
  129. {
  130. if (this.m_captureLuaGC != value)
  131. {
  132. this.m_captureLuaGC = value;
  133. this.Save();
  134. }
  135. }
  136. }
  137. public bool isNeedCapture
  138. {
  139. get
  140. {
  141. return this.m_isNeedCapture;
  142. }
  143. set
  144. {
  145. if (this.m_isNeedCapture != value)
  146. {
  147. this.m_isNeedCapture = value;
  148. this.Save();
  149. }
  150. }
  151. }
  152. public string assMd5
  153. {
  154. get
  155. {
  156. return this.m_assMd5;
  157. }
  158. set
  159. {
  160. if (!(this.m_assMd5 == value))
  161. {
  162. this.m_assMd5 = value;
  163. this.Save();
  164. }
  165. }
  166. }
  167. public bool isInited
  168. {
  169. get
  170. {
  171. return this.m_isInited;
  172. }
  173. set
  174. {
  175. if (this.m_isInited != value)
  176. {
  177. this.m_isInited = value;
  178. this.Save();
  179. }
  180. }
  181. }
  182. public bool discardInvalid
  183. {
  184. get
  185. {
  186. return m_discardInvalid;
  187. }
  188. set
  189. {
  190. if (m_discardInvalid != value)
  191. {
  192. m_discardInvalid = value;
  193. this.Save();
  194. }
  195. }
  196. }
  197. public int captureMonoGC
  198. {
  199. get
  200. {
  201. return this.m_captureMonoGC;
  202. }
  203. set
  204. {
  205. if (this.m_captureMonoGC != value)
  206. {
  207. this.m_captureMonoGC = value;
  208. this.Save();
  209. }
  210. }
  211. }
  212. public int captureFrameRate
  213. {
  214. get
  215. {
  216. return this.m_captureFrameRate;
  217. }
  218. set
  219. {
  220. if (this.m_captureFrameRate != value)
  221. {
  222. this.m_captureFrameRate = value;
  223. this.Save();
  224. }
  225. }
  226. }
  227. public string ip
  228. {
  229. get
  230. {
  231. return this.m_ip;
  232. }
  233. set
  234. {
  235. if (!(this.m_ip == value))
  236. {
  237. this.m_ip = value;
  238. this.Save();
  239. }
  240. }
  241. }
  242. public int port
  243. {
  244. get
  245. {
  246. return this.m_port;
  247. }
  248. set
  249. {
  250. if (this.m_port != value)
  251. {
  252. this.m_port = value;
  253. this.Save();
  254. }
  255. }
  256. }
  257. public void Save()
  258. {
  259. #if UNITY_EDITOR
  260. string text = "Assets/Resources/LuaDeepProfilerSettings.bytes";
  261. if (!Directory.Exists("Assets/Resources"))
  262. {
  263. Directory.CreateDirectory("Assets/Resources");
  264. }
  265. FileStream output = new FileStream(text, FileMode.Create);
  266. BinaryWriter binaryWriter = new BinaryWriter(output);
  267. binaryWriter.Write(this.m_isDeepMonoProfiler);
  268. binaryWriter.Write(this.m_isDeepLuaProfiler);
  269. binaryWriter.Write(this.m_captureLuaGC);
  270. binaryWriter.Write(this.m_isInited);
  271. binaryWriter.Write(this.m_isNeedCapture);
  272. binaryWriter.Write(this.m_captureMonoGC);
  273. binaryWriter.Write(this.m_captureFrameRate);
  274. byte[] bytes = Encoding.UTF8.GetBytes(this.m_assMd5);
  275. binaryWriter.Write(bytes.Length);
  276. binaryWriter.Write(bytes);
  277. bytes = Encoding.UTF8.GetBytes(this.m_ip);
  278. binaryWriter.Write(bytes.Length);
  279. binaryWriter.Write(bytes);
  280. binaryWriter.Write(this.m_port);
  281. binaryWriter.Write(m_discardInvalid);
  282. binaryWriter.Write(m_isCleanMode);
  283. output.Flush();
  284. binaryWriter.Close();
  285. #endif
  286. }
  287. // Token: 0x060000C9 RID: 201 RVA: 0x00006674 File Offset: 0x00004A74
  288. public static LuaDeepProfilerSetting Load()
  289. {
  290. LuaDeepProfilerSetting luaDeepProfilerSetting = new LuaDeepProfilerSetting();
  291. byte[] datas = null;
  292. #if UNITY_EDITOR
  293. string text = "Assets/Resources/LuaDeepProfilerSettings.bytes";
  294. if (!File.Exists(text))
  295. {
  296. luaDeepProfilerSetting.Save();
  297. }
  298. datas = File.ReadAllBytes(text);
  299. #else
  300. TextAsset textAsset = null;
  301. string path = Application.persistentDataPath + "/LuaDeepProfilerSettings.bytes";
  302. if (File.Exists(path))
  303. {
  304. datas = File.ReadAllBytes(path);
  305. }
  306. else
  307. {
  308. textAsset = Resources.Load<TextAsset>("LuaDeepProfilerSettings");
  309. datas = textAsset != null ? textAsset.bytes : null;
  310. }
  311. #endif
  312. if (datas != null)
  313. {
  314. MemoryStream memoryStream = new MemoryStream(datas);
  315. try
  316. {
  317. BinaryReader binaryReader = new BinaryReader(memoryStream);
  318. luaDeepProfilerSetting.m_isDeepMonoProfiler = binaryReader.ReadBoolean();
  319. luaDeepProfilerSetting.m_isDeepLuaProfiler = binaryReader.ReadBoolean();
  320. luaDeepProfilerSetting.m_captureLuaGC = binaryReader.ReadInt32();
  321. luaDeepProfilerSetting.m_isInited = binaryReader.ReadBoolean();
  322. luaDeepProfilerSetting.m_isNeedCapture = binaryReader.ReadBoolean();
  323. luaDeepProfilerSetting.m_captureMonoGC = binaryReader.ReadInt32();
  324. luaDeepProfilerSetting.m_captureFrameRate = binaryReader.ReadInt32();
  325. int count = binaryReader.ReadInt32();
  326. luaDeepProfilerSetting.m_assMd5 = Encoding.UTF8.GetString(binaryReader.ReadBytes(count));
  327. count = binaryReader.ReadInt32();
  328. luaDeepProfilerSetting.m_ip = Encoding.UTF8.GetString(binaryReader.ReadBytes(count));
  329. luaDeepProfilerSetting.m_port = binaryReader.ReadInt32();
  330. luaDeepProfilerSetting.m_discardInvalid = binaryReader.ReadBoolean();
  331. luaDeepProfilerSetting.m_isCleanMode = binaryReader.ReadBoolean();
  332. binaryReader.Close();
  333. }
  334. catch
  335. {
  336. #if UNITY_EDITOR
  337. memoryStream.Dispose();
  338. File.Delete(text);
  339. return LuaDeepProfilerSetting.Load();
  340. #endif
  341. }
  342. }
  343. else
  344. {
  345. luaDeepProfilerSetting.Save();
  346. }
  347. #if !UNITY_EDITOR
  348. if (!File.Exists(path))
  349. {
  350. File.WriteAllBytes(path, datas);
  351. }
  352. if (textAsset != null)
  353. {
  354. Resources.UnloadAsset(textAsset);
  355. }
  356. #endif
  357. return luaDeepProfilerSetting;
  358. }
  359. public const string SettingsAssetName = "LuaDeepProfilerSettings";
  360. private static LuaDeepProfilerSetting instance;
  361. private bool m_isDeepMonoProfiler = false;
  362. private bool m_isDeepLuaProfiler = false;
  363. private bool m_isCleanMode = false;
  364. private int m_captureLuaGC = 51200;
  365. private bool m_isNeedCapture = false;
  366. private bool m_discardInvalid = true;
  367. private string m_assMd5 = "";
  368. private bool m_isInited = false;
  369. private int m_captureMonoGC = 51200;
  370. private int m_captureFrameRate = 30;
  371. private string m_ip = "127.0.0.1";
  372. private int m_port = 2333;
  373. }
  374. }
  375. #endif