DeviceInfoCounterData.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. #region copyright
  2. //-------------------------------------------------------
  3. // Copyright (C) Dmitriy Yukhanov [https://codestage.net]
  4. //-------------------------------------------------------
  5. #endregion
  6. namespace CodeStage.AdvancedFPSCounter.CountersData
  7. {
  8. using System;
  9. using System.Text;
  10. using Labels;
  11. using UnityEngine;
  12. /// <summary>
  13. /// Shows additional device information.
  14. /// </summary>
  15. [Serializable]
  16. public class DeviceInfoCounterData : StaticCounterData
  17. {
  18. // ----------------------------------------------------------------------------
  19. // properties exposed to the inspector
  20. // ----------------------------------------------------------------------------
  21. #region Platform
  22. [Tooltip("Shows operating system & platform info.")]
  23. [SerializeField]
  24. private bool platform = true;
  25. /// <summary>
  26. /// Shows operating system & platform info.
  27. /// </summary>
  28. public bool Platform
  29. {
  30. get { return platform; }
  31. set
  32. {
  33. if (platform == value || !Application.isPlaying) return;
  34. platform = value;
  35. if (!enabled) return;
  36. Refresh();
  37. }
  38. }
  39. #endregion
  40. #region CpuModel
  41. [Tooltip("CPU model and cores (including virtual cores from Intel's Hyper Threading) count.")]
  42. [SerializeField]
  43. private bool cpuModel = true;
  44. /// <summary>
  45. /// Shows CPU model and cores (including virtual cores from Intel's Hyper Threading) count.
  46. /// </summary>
  47. public bool CpuModel
  48. {
  49. get { return cpuModel; }
  50. set
  51. {
  52. if (cpuModel == value || !Application.isPlaying) return;
  53. cpuModel = value;
  54. if (!enabled) return;
  55. Refresh();
  56. }
  57. }
  58. [Tooltip("Check to show CPU model on new line.")]
  59. [SerializeField]
  60. private bool cpuModelNewLine = true;
  61. /// <summary>
  62. /// Controls if CPU model should be placed on new line or not.
  63. /// </summary>
  64. public bool CpuModelNewLine
  65. {
  66. get { return cpuModelNewLine; }
  67. set
  68. {
  69. if (cpuModelNewLine == value || !Application.isPlaying) return;
  70. cpuModelNewLine = value;
  71. if (!enabled) return;
  72. Refresh();
  73. }
  74. }
  75. #endregion
  76. #region GpuModel
  77. [Tooltip("Shows GPU model name.")]
  78. [SerializeField]
  79. private bool gpuModel = true;
  80. /// <summary>
  81. /// Shows GPU model.
  82. /// </summary>
  83. public bool GpuModel
  84. {
  85. get { return gpuModel; }
  86. set
  87. {
  88. if (gpuModel == value || !Application.isPlaying) return;
  89. gpuModel = value;
  90. if (!enabled) return;
  91. Refresh();
  92. }
  93. }
  94. [Tooltip("Check to show GPU model on new line.")]
  95. [SerializeField]
  96. private bool gpuModelNewLine = true;
  97. /// <summary>
  98. /// Controls if GPU model should be placed on new line or not.
  99. /// </summary>
  100. public bool GpuModelNewLine
  101. {
  102. get { return gpuModelNewLine; }
  103. set
  104. {
  105. if (gpuModelNewLine == value || !Application.isPlaying) return;
  106. gpuModelNewLine = value;
  107. if (!enabled) return;
  108. Refresh();
  109. }
  110. }
  111. #endregion
  112. #region GpuApi
  113. [Tooltip("Shows graphics API version and type (if possible).")]
  114. [SerializeField]
  115. private bool gpuApi = true;
  116. /// <summary>
  117. /// Shows graphics API version and type (if possible).
  118. /// </summary>
  119. public bool GpuApi
  120. {
  121. get { return gpuApi; }
  122. set
  123. {
  124. if (gpuApi == value || !Application.isPlaying) return;
  125. gpuApi = value;
  126. if (!enabled) return;
  127. Refresh();
  128. }
  129. }
  130. [Tooltip("Check to show graphics API version on new line.")]
  131. [SerializeField]
  132. private bool gpuApiNewLine = true;
  133. /// <summary>
  134. /// Controls if graphics API version should be placed on new line or not.
  135. /// </summary>
  136. public bool GpuApiNewLine
  137. {
  138. get { return gpuApiNewLine; }
  139. set
  140. {
  141. if (gpuApiNewLine == value || !Application.isPlaying) return;
  142. gpuApiNewLine = value;
  143. if (!enabled) return;
  144. Refresh();
  145. }
  146. }
  147. #endregion
  148. #region GpuSpec
  149. [Tooltip("Shows graphics supported shader model (if possible), approximate pixel fill-rate (if possible) and total Video RAM size (if possible).")]
  150. [SerializeField]
  151. private bool gpuSpec = true;
  152. /// <summary>
  153. /// Shows graphics supported shader model (if possible), approximate pixel fill-rate (if possible) and total Video RAM size (if possible).
  154. /// </summary>
  155. public bool GpuSpec
  156. {
  157. get { return gpuSpec; }
  158. set
  159. {
  160. if (gpuSpec == value || !Application.isPlaying) return;
  161. gpuSpec = value;
  162. if (!enabled) return;
  163. Refresh();
  164. }
  165. }
  166. [Tooltip("Check to show graphics specs on new line.")]
  167. [SerializeField]
  168. private bool gpuSpecNewLine = true;
  169. /// <summary>
  170. /// Controls if graphics specs should be placed on new line or not.
  171. /// </summary>
  172. public bool GpuSpecNewLine
  173. {
  174. get { return gpuSpecNewLine; }
  175. set
  176. {
  177. if (gpuSpecNewLine == value || !Application.isPlaying) return;
  178. gpuSpecNewLine = value;
  179. if (!enabled) return;
  180. Refresh();
  181. }
  182. }
  183. #endregion
  184. #region RAMSize
  185. [Tooltip("Shows total RAM size.")]
  186. [SerializeField]
  187. private bool ramSize = true;
  188. /// <summary>
  189. /// Shows total RAM size.
  190. /// </summary>
  191. public bool RamSize
  192. {
  193. get { return ramSize; }
  194. set
  195. {
  196. if (ramSize == value || !Application.isPlaying) return;
  197. ramSize = value;
  198. if (!enabled) return;
  199. Refresh();
  200. }
  201. }
  202. [Tooltip("Check to show RAM size on new line.")]
  203. [SerializeField]
  204. private bool ramSizeNewLine = true;
  205. /// <summary>
  206. /// Controls if RAM size should be placed on new line or not.
  207. /// </summary>
  208. public bool RamSizeNewLine
  209. {
  210. get { return ramSizeNewLine; }
  211. set
  212. {
  213. if (ramSizeNewLine == value || !Application.isPlaying) return;
  214. ramSizeNewLine = value;
  215. if (!enabled) return;
  216. Refresh();
  217. }
  218. }
  219. #endregion
  220. #region ScreenData
  221. [Tooltip("Shows screen resolution, size and DPI (if possible).")]
  222. [SerializeField]
  223. private bool screenData = true;
  224. /// <summary>
  225. /// Shows screen resolution, size and DPI (if possible).
  226. /// </summary>
  227. public bool ScreenData
  228. {
  229. get { return screenData; }
  230. set
  231. {
  232. if (screenData == value || !Application.isPlaying) return;
  233. screenData = value;
  234. if (!enabled) return;
  235. Refresh();
  236. }
  237. }
  238. [Tooltip("Check to show screen data on new line.")]
  239. [SerializeField]
  240. private bool screenDataNewLine = true;
  241. /// <summary>
  242. /// Controls if screen data should be placed on new line or not.
  243. /// </summary>
  244. public bool ScreenDataNewLine
  245. {
  246. get { return screenDataNewLine; }
  247. set
  248. {
  249. if (screenDataNewLine == value || !Application.isPlaying) return;
  250. screenDataNewLine = value;
  251. if (!enabled) return;
  252. Refresh();
  253. }
  254. }
  255. #endregion
  256. #region DeviceModel
  257. [Tooltip("Shows device model. Actual for mobile devices.")]
  258. [SerializeField]
  259. private bool deviceModel;
  260. /// <summary>
  261. /// Shows device model.
  262. /// </summary>
  263. public bool DeviceModel
  264. {
  265. get { return deviceModel; }
  266. set
  267. {
  268. if (deviceModel == value || !Application.isPlaying) return;
  269. deviceModel = value;
  270. if (!enabled) return;
  271. Refresh();
  272. }
  273. }
  274. [Tooltip("Check to show device model on new line.")]
  275. [SerializeField]
  276. private bool deviceModelNewLine = true;
  277. /// <summary>
  278. /// Controls if device model should be placed on new line or not.
  279. /// </summary>
  280. public bool DeviceModelNewLine
  281. {
  282. get { return deviceModelNewLine; }
  283. set
  284. {
  285. if (deviceModelNewLine == value || !Application.isPlaying) return;
  286. deviceModelNewLine = value;
  287. if (!enabled) return;
  288. Refresh();
  289. }
  290. }
  291. #endregion
  292. // ----------------------------------------------------------------------------
  293. // properties only accessible from code
  294. // ----------------------------------------------------------------------------
  295. public string LastValue { get; private set; }
  296. // ----------------------------------------------------------------------------
  297. // constructor
  298. // ----------------------------------------------------------------------------
  299. internal DeviceInfoCounterData()
  300. {
  301. color = new Color32(172, 172, 172, 255);
  302. anchor = LabelAnchor.LowerLeft;
  303. }
  304. // ----------------------------------------------------------------------------
  305. // internal methods
  306. // ----------------------------------------------------------------------------
  307. internal override void UpdateValue(bool force)
  308. {
  309. if (!inited && HasData())
  310. {
  311. Activate();
  312. return;
  313. }
  314. if (inited && !HasData())
  315. {
  316. Deactivate();
  317. return;
  318. }
  319. if (!enabled) return;
  320. var hasContent = false;
  321. if (text == null)
  322. {
  323. text = new StringBuilder(500);
  324. }
  325. else
  326. {
  327. text.Length = 0;
  328. }
  329. if (platform)
  330. {
  331. text.Append("OS: ").Append(SystemInfo.operatingSystem)
  332. .Append(" [").Append(Application.platform).Append("]");
  333. hasContent = true;
  334. }
  335. if (cpuModel)
  336. {
  337. if (hasContent) text.Append(cpuModelNewLine ? AFPSCounter.NewLine : ' ');
  338. text.Append("CPU: ").Append(SystemInfo.processorType).Append(" [").Append(SystemInfo.processorCount).Append(" cores]");
  339. hasContent = true;
  340. }
  341. if (gpuModel)
  342. {
  343. if (hasContent) text.Append(gpuModelNewLine ? AFPSCounter.NewLine : ' ');
  344. text.Append("GPU: ").Append(SystemInfo.graphicsDeviceName);
  345. hasContent = true;
  346. }
  347. if (gpuApi)
  348. {
  349. if (hasContent) text.Append(gpuApiNewLine ? AFPSCounter.NewLine : ' ');
  350. if (gpuApiNewLine || !gpuModel)
  351. {
  352. text.Append("GPU: ");
  353. }
  354. text.Append(SystemInfo.graphicsDeviceVersion);
  355. text.Append(" [").Append(SystemInfo.graphicsDeviceType).Append("]");
  356. hasContent = true;
  357. }
  358. if (gpuSpec)
  359. {
  360. if (hasContent) text.Append(gpuSpecNewLine ? AFPSCounter.NewLine : ' ');
  361. if (gpuSpecNewLine || (!gpuModel && !gpuApi))
  362. {
  363. text.Append("GPU: SM: ");
  364. }
  365. else
  366. {
  367. text.Append("SM: ");
  368. }
  369. var sm = SystemInfo.graphicsShaderLevel;
  370. if (sm >= 10 && sm <= 99)
  371. {
  372. // getting first and second digits from sm
  373. text.Append(sm /= 10).Append('.').Append(sm / 10);
  374. }
  375. else
  376. {
  377. text.Append("N/A");
  378. }
  379. text.Append(", VRAM: ");
  380. var vram = SystemInfo.graphicsMemorySize;
  381. if (vram > 0)
  382. {
  383. text.Append(vram).Append(" MB");
  384. }
  385. else
  386. {
  387. text.Append("N/A");
  388. }
  389. hasContent = true;
  390. }
  391. if (ramSize)
  392. {
  393. if (hasContent) text.Append(ramSizeNewLine ? AFPSCounter.NewLine : ' ');
  394. var ram = SystemInfo.systemMemorySize;
  395. if (ram > 0)
  396. {
  397. text.Append("RAM: ").Append(ram).Append(" MB");
  398. hasContent = true;
  399. }
  400. else
  401. {
  402. hasContent = false;
  403. }
  404. }
  405. if (screenData)
  406. {
  407. if (hasContent) text.Append(screenDataNewLine ? AFPSCounter.NewLine : ' ');
  408. var res = Screen.currentResolution;
  409. text.Append("SCR: ").Append(res.width).Append("x").Append(res.height).Append("@").Append(res.refreshRate).Append("Hz [window size: ").Append(Screen.width).Append("x").Append(Screen.height);
  410. var dpi = Screen.dpi;
  411. if (dpi > 0)
  412. {
  413. text.Append(", DPI: ").Append(dpi).Append("]");
  414. }
  415. else
  416. {
  417. text.Append("]");
  418. }
  419. hasContent = true;
  420. }
  421. if (deviceModel)
  422. {
  423. if (hasContent) text.Append(deviceModelNewLine ? AFPSCounter.NewLine : ' ');
  424. text.Append("Model: ").Append(SystemInfo.deviceModel);
  425. }
  426. LastValue = text.ToString();
  427. if (main.OperationMode == OperationMode.Normal)
  428. {
  429. text.Insert(0, colorCached);
  430. text.Append("</color>");
  431. ApplyTextStyles();
  432. }
  433. else
  434. {
  435. text.Length = 0;
  436. }
  437. dirty = true;
  438. }
  439. // ----------------------------------------------------------------------------
  440. // protected methods
  441. // ----------------------------------------------------------------------------
  442. protected override bool HasData()
  443. {
  444. return cpuModel || gpuModel || ramSize || screenData;
  445. }
  446. protected override void CacheCurrentColor()
  447. {
  448. colorCached = "<color=#" + AFPSCounter.Color32ToHex(color) + ">";
  449. }
  450. }
  451. }