You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

709 lines
30 KiB

  1. /* ---------------------------------------
  2. * Author: Martin Pane (martintayx@gmail.com) (@tayx94)
  3. * Collaborators: Lars Aalbertsen (@Rockylars)
  4. * Project: Graphy - Ultimate Stats Monitor
  5. * Date: 15-Dec-17
  6. * Studio: Tayx
  7. *
  8. * This project is released under the MIT license.
  9. * Attribution is not required, but it is always welcomed!
  10. * -------------------------------------*/
  11. using System;
  12. using UnityEngine;
  13. using Tayx.Graphy.Audio;
  14. using Tayx.Graphy.Fps;
  15. using Tayx.Graphy.Ram;
  16. using Tayx.Graphy.Utils;
  17. using Tayx.Graphy.Advanced;
  18. namespace Tayx.Graphy
  19. {
  20. //[ExecuteInEditMode]
  21. public class GraphyManager : G_Singleton<GraphyManager>
  22. {
  23. /* ----- TODO: ----------------------------
  24. * Add summaries to the variables.
  25. * Add summaries to the functions.
  26. * --------------------------------------*/
  27. protected GraphyManager () { }
  28. //Enums
  29. #region Enums -> Public
  30. public enum Mode
  31. {
  32. FULL = 0,
  33. LIGHT = 1
  34. }
  35. public enum ModuleType
  36. {
  37. FPS = 0,
  38. RAM = 1,
  39. AUDIO = 2,
  40. ADVANCED = 3
  41. }
  42. public enum ModuleState
  43. {
  44. FULL = 0,
  45. TEXT = 1,
  46. BASIC = 2,
  47. BACKGROUND = 3,
  48. OFF = 4
  49. }
  50. public enum ModulePosition
  51. {
  52. TOP_RIGHT = 0,
  53. TOP_LEFT = 1,
  54. BOTTOM_RIGHT = 2,
  55. BOTTOM_LEFT = 3,
  56. FREE = 4
  57. }
  58. public enum LookForAudioListener
  59. {
  60. ALWAYS,
  61. ON_SCENE_LOAD,
  62. NEVER
  63. }
  64. public enum ModulePreset
  65. {
  66. FPS_BASIC = 0,
  67. FPS_TEXT = 1,
  68. FPS_FULL = 2,
  69. FPS_TEXT_RAM_TEXT = 3,
  70. FPS_FULL_RAM_TEXT = 4,
  71. FPS_FULL_RAM_FULL = 5,
  72. FPS_TEXT_RAM_TEXT_AUDIO_TEXT = 6,
  73. FPS_FULL_RAM_TEXT_AUDIO_TEXT = 7,
  74. FPS_FULL_RAM_FULL_AUDIO_TEXT = 8,
  75. FPS_FULL_RAM_FULL_AUDIO_FULL = 9,
  76. FPS_FULL_RAM_FULL_AUDIO_FULL_ADVANCED_FULL = 10,
  77. FPS_BASIC_ADVANCED_FULL = 11
  78. }
  79. #endregion
  80. #region Variables -> Serialized Private
  81. [SerializeField] private Mode m_graphyMode = Mode.FULL;
  82. [SerializeField] private bool m_enableOnStartup = true;
  83. [SerializeField] private bool m_keepAlive = true;
  84. [SerializeField] private bool m_background = true;
  85. [SerializeField] private Color m_backgroundColor = new Color(0, 0, 0, 0.3f);
  86. [SerializeField] private bool m_enableHotkeys = true;
  87. [SerializeField] private KeyCode m_toggleModeKeyCode = KeyCode.G;
  88. [SerializeField] private bool m_toggleModeCtrl = true;
  89. [SerializeField] private bool m_toggleModeAlt = false;
  90. [SerializeField] private KeyCode m_toggleActiveKeyCode = KeyCode.H;
  91. [SerializeField] private bool m_toggleActiveCtrl = true;
  92. [SerializeField] private bool m_toggleActiveAlt = false;
  93. [SerializeField] private ModulePosition m_graphModulePosition = ModulePosition.TOP_RIGHT;
  94. // Fps ---------------------------------------------------------------------------
  95. [SerializeField] private ModuleState m_fpsModuleState = ModuleState.FULL;
  96. [Range(0, 200)]
  97. [Tooltip("Time (in seconds) to reset the minimum and maximum framerates if they don't change in the specified time. Set to 0 if you don't want it to reset.")]
  98. [SerializeField] private int m_timeToResetMinMaxFps = 10;
  99. [SerializeField] private Color m_goodFpsColor = new Color32(118, 212, 58, 255);
  100. [SerializeField] private int m_goodFpsThreshold = 60;
  101. [SerializeField] private Color m_cautionFpsColor = new Color32(243, 232, 0, 255);
  102. [SerializeField] private int m_cautionFpsThreshold = 30;
  103. [SerializeField] private Color m_criticalFpsColor = new Color32(220, 41, 30, 255);
  104. [Range(10, 300)]
  105. [SerializeField] private int m_fpsGraphResolution = 150;
  106. [Range(1, 200)]
  107. [SerializeField] private int m_fpsTextUpdateRate = 3; // 3 updates per sec.
  108. // Ram ---------------------------------------------------------------------------
  109. [SerializeField] private ModuleState m_ramModuleState = ModuleState.FULL;
  110. [SerializeField] private Color m_allocatedRamColor = new Color32(255, 190, 60, 255);
  111. [SerializeField] private Color m_reservedRamColor = new Color32(205, 84, 229, 255);
  112. [SerializeField] private Color m_monoRamColor = new Color(0.3f, 0.65f, 1f, 1);
  113. [Range(10, 300)]
  114. [SerializeField] private int m_ramGraphResolution = 150;
  115. [Range(1, 200)]
  116. [SerializeField] private int m_ramTextUpdateRate = 3; // 3 updates per sec.
  117. // Audio -------------------------------------------------------------------------
  118. [SerializeField] private ModuleState m_audioModuleState = ModuleState.FULL;
  119. [SerializeField] private LookForAudioListener m_findAudioListenerInCameraIfNull = LookForAudioListener.ON_SCENE_LOAD;
  120. [SerializeField] private AudioListener m_audioListener = null;
  121. [SerializeField] private Color m_audioGraphColor = Color.white;
  122. [Range(10, 300)]
  123. [SerializeField] private int m_audioGraphResolution = 81;
  124. [Range(1, 200)]
  125. [SerializeField] private int m_audioTextUpdateRate = 3; // 3 updates per sec.
  126. [SerializeField] private FFTWindow m_FFTWindow = FFTWindow.Blackman;
  127. [Tooltip("Must be a power of 2 and between 64-8192")]
  128. [SerializeField] private int m_spectrumSize = 512;
  129. // Advanced ----------------------------------------------------------------------
  130. [SerializeField] private ModulePosition m_advancedModulePosition = ModulePosition.BOTTOM_LEFT;
  131. [SerializeField] private ModuleState m_advancedModuleState = ModuleState.FULL;
  132. #endregion
  133. #region Variables -> Private
  134. private bool m_initialized = false;
  135. private bool m_active = true;
  136. private bool m_focused = true;
  137. private G_FpsManager m_fpsManager = null;
  138. private G_RamManager m_ramManager = null;
  139. private G_AudioManager m_audioManager = null;
  140. private G_AdvancedData m_advancedData = null;
  141. private G_FpsMonitor m_fpsMonitor = null;
  142. private G_RamMonitor m_ramMonitor = null;
  143. private G_AudioMonitor m_audioMonitor = null;
  144. private ModulePreset m_modulePresetState = ModulePreset.FPS_BASIC_ADVANCED_FULL;
  145. #endregion
  146. //TODO: Maybe sort these into Get and GetSet sections.
  147. #region Properties -> Public
  148. public Mode GraphyMode { get { return m_graphyMode; }
  149. set { m_graphyMode = value; UpdateAllParameters(); } }
  150. public bool EnableOnStartup { get { return m_enableOnStartup; } }
  151. public bool KeepAlive { get { return m_keepAlive; } }
  152. public bool Background { get { return m_background; }
  153. set { m_background = value; UpdateAllParameters(); } }
  154. public Color BackgroundColor { get { return m_backgroundColor; }
  155. set { m_backgroundColor = value; UpdateAllParameters(); } }
  156. public ModulePosition GraphModulePosition
  157. {
  158. get { return m_graphModulePosition; }
  159. set
  160. {
  161. m_graphModulePosition = value;
  162. m_fpsManager .SetPosition(m_graphModulePosition);
  163. m_ramManager .SetPosition(m_graphModulePosition);
  164. m_audioManager .SetPosition(m_graphModulePosition);
  165. }
  166. }
  167. // Fps ---------------------------------------------------------------------------
  168. // Setters & Getters
  169. public ModuleState FpsModuleState { get { return m_fpsModuleState; }
  170. set { m_fpsModuleState = value; m_fpsManager.SetState(m_fpsModuleState); } }
  171. public int TimeToResetMinMaxFps { get { return m_timeToResetMinMaxFps; }
  172. set { m_timeToResetMinMaxFps = value; m_fpsManager.UpdateParameters(); } }
  173. public Color GoodFPSColor { get { return m_goodFpsColor; }
  174. set { m_goodFpsColor = value; m_fpsManager.UpdateParameters(); } }
  175. public Color CautionFPSColor { get { return m_cautionFpsColor; }
  176. set { m_cautionFpsColor = value; m_fpsManager.UpdateParameters(); } }
  177. public Color CriticalFPSColor { get { return m_criticalFpsColor; }
  178. set { m_criticalFpsColor = value; m_fpsManager.UpdateParameters(); } }
  179. public int GoodFPSThreshold { get { return m_goodFpsThreshold; }
  180. set { m_goodFpsThreshold = value; m_fpsManager.UpdateParameters(); } }
  181. public int CautionFPSThreshold { get { return m_cautionFpsThreshold; }
  182. set { m_cautionFpsThreshold = value; m_fpsManager.UpdateParameters(); } }
  183. public int FpsGraphResolution { get { return m_fpsGraphResolution; }
  184. set { m_fpsGraphResolution = value; m_fpsManager.UpdateParameters(); } }
  185. public int FpsTextUpdateRate { get { return m_fpsTextUpdateRate; }
  186. set { m_fpsTextUpdateRate = value; m_fpsManager.UpdateParameters(); } }
  187. // Getters
  188. public float CurrentFPS { get { return m_fpsMonitor.CurrentFPS; } }
  189. public float AverageFPS { get { return m_fpsMonitor.AverageFPS; } }
  190. public float MinFPS { get { return m_fpsMonitor.MinFPS; } }
  191. public float MaxFPS { get { return m_fpsMonitor.MaxFPS; } }
  192. // Ram ---------------------------------------------------------------------------
  193. // Setters & Getters
  194. public ModuleState RamModuleState { get { return m_ramModuleState; }
  195. set { m_ramModuleState = value; m_ramManager.SetState(m_ramModuleState); } }
  196. public Color AllocatedRamColor { get { return m_allocatedRamColor; }
  197. set { m_allocatedRamColor = value; m_ramManager.UpdateParameters(); } }
  198. public Color ReservedRamColor { get { return m_reservedRamColor; }
  199. set { m_reservedRamColor = value; m_ramManager.UpdateParameters(); } }
  200. public Color MonoRamColor { get { return m_monoRamColor; }
  201. set { m_monoRamColor = value; m_ramManager.UpdateParameters(); } }
  202. public int RamGraphResolution { get { return m_ramGraphResolution; }
  203. set { m_ramGraphResolution = value; m_ramManager.UpdateParameters(); } }
  204. public int RamTextUpdateRate { get { return m_ramTextUpdateRate; }
  205. set { m_ramTextUpdateRate = value; m_ramManager.UpdateParameters(); } }
  206. // Getters
  207. public float AllocatedRam { get { return m_ramMonitor.AllocatedRam; } }
  208. public float ReservedRam { get { return m_ramMonitor.ReservedRam; } }
  209. public float MonoRam { get { return m_ramMonitor.MonoRam; } }
  210. // Audio -------------------------------------------------------------------------
  211. // Setters & Getters
  212. public ModuleState AudioModuleState { get { return m_audioModuleState; }
  213. set { m_audioModuleState = value; m_audioManager.SetState(m_audioModuleState); } }
  214. public AudioListener AudioListener { get { return m_audioListener; }
  215. set { m_audioListener = value; m_audioManager.UpdateParameters(); } }
  216. public LookForAudioListener
  217. FindAudioListenerInCameraIfNull { get { return m_findAudioListenerInCameraIfNull; }
  218. set { m_findAudioListenerInCameraIfNull = value; m_audioManager.UpdateParameters(); } }
  219. public Color AudioGraphColor { get { return m_audioGraphColor; }
  220. set { m_audioGraphColor = value; m_audioManager.UpdateParameters(); } }
  221. public int AudioGraphResolution { get { return m_audioGraphResolution; }
  222. set { m_audioGraphResolution = value; m_audioManager.UpdateParameters(); } }
  223. public int AudioTextUpdateRate { get { return m_audioTextUpdateRate; }
  224. set { m_audioTextUpdateRate = value; m_audioManager.UpdateParameters(); } }
  225. public FFTWindow FftWindow { get { return m_FFTWindow; }
  226. set { m_FFTWindow = value; m_audioManager.UpdateParameters(); } }
  227. public int SpectrumSize { get { return m_spectrumSize; }
  228. set { m_spectrumSize = value; m_audioManager.UpdateParameters(); } }
  229. // Getters
  230. /// <summary>
  231. /// Current audio spectrum from the specified AudioListener.
  232. /// </summary>
  233. public float[] Spectrum { get { return m_audioMonitor.Spectrum; } }
  234. /// <summary>
  235. /// Maximum DB registered in the current spectrum.
  236. /// </summary>
  237. public float MaxDB { get { return m_audioMonitor.MaxDB; } }
  238. // Advanced ---------------------------------------------------------------------
  239. // Setters & Getters
  240. public ModuleState AdvancedModuleState { get { return m_advancedModuleState; }
  241. set { m_advancedModuleState = value; m_advancedData.SetState(m_advancedModuleState); } }
  242. public ModulePosition AdvancedModulePosition { get { return m_advancedModulePosition; }
  243. set { m_advancedModulePosition = value; m_advancedData.SetPosition(m_advancedModulePosition); } }
  244. #endregion
  245. #region Methods -> Unity Callbacks
  246. private void Start()
  247. {
  248. Init();
  249. }
  250. private void Update()
  251. {
  252. if (m_focused && m_enableHotkeys)
  253. {
  254. CheckForHotkeyPresses();
  255. }
  256. }
  257. private void OnApplicationFocus(bool isFocused)
  258. {
  259. m_focused = isFocused;
  260. if (m_initialized && isFocused)
  261. {
  262. RefreshAllParameters();
  263. }
  264. }
  265. #endregion
  266. #region Methods -> Public
  267. public void SetModulePosition(ModuleType moduleType, ModulePosition modulePosition)
  268. {
  269. switch (moduleType)
  270. {
  271. case ModuleType.FPS:
  272. case ModuleType.RAM:
  273. case ModuleType.AUDIO:
  274. m_graphModulePosition = modulePosition;
  275. m_ramManager.SetPosition(modulePosition);
  276. m_fpsManager.SetPosition(modulePosition);
  277. m_audioManager.SetPosition(modulePosition);
  278. break;
  279. case ModuleType.ADVANCED:
  280. m_advancedData.SetPosition(modulePosition);
  281. break;
  282. }
  283. }
  284. public void SetModuleMode(ModuleType moduleType, ModuleState moduleState)
  285. {
  286. switch (moduleType)
  287. {
  288. case ModuleType.FPS:
  289. m_fpsManager.SetState(moduleState);
  290. break;
  291. case ModuleType.RAM:
  292. m_ramManager.SetState(moduleState);
  293. break;
  294. case ModuleType.AUDIO:
  295. m_audioManager.SetState(moduleState);
  296. break;
  297. case ModuleType.ADVANCED:
  298. m_advancedData.SetState(moduleState);
  299. break;
  300. }
  301. }
  302. public void ToggleModes()
  303. {
  304. if ((int)m_modulePresetState >= Enum.GetNames(typeof(ModulePreset)).Length - 1)
  305. {
  306. m_modulePresetState = 0;
  307. }
  308. else
  309. {
  310. m_modulePresetState++;
  311. }
  312. SetPreset(m_modulePresetState);
  313. }
  314. public void SetPreset(ModulePreset modulePreset)
  315. {
  316. m_modulePresetState = modulePreset;
  317. switch (m_modulePresetState)
  318. {
  319. case ModulePreset.FPS_BASIC:
  320. m_fpsManager.SetState(ModuleState.BASIC);
  321. m_ramManager.SetState(ModuleState.OFF);
  322. m_audioManager.SetState(ModuleState.OFF);
  323. m_advancedData.SetState(ModuleState.OFF);
  324. break;
  325. case ModulePreset.FPS_TEXT:
  326. m_fpsManager.SetState(ModuleState.TEXT);
  327. m_ramManager.SetState(ModuleState.OFF);
  328. m_audioManager.SetState(ModuleState.OFF);
  329. m_advancedData.SetState(ModuleState.OFF);
  330. break;
  331. case ModulePreset.FPS_FULL:
  332. m_fpsManager.SetState(ModuleState.FULL);
  333. m_ramManager.SetState(ModuleState.OFF);
  334. m_audioManager.SetState(ModuleState.OFF);
  335. m_advancedData.SetState(ModuleState.OFF);
  336. break;
  337. case ModulePreset.FPS_TEXT_RAM_TEXT:
  338. m_fpsManager.SetState(ModuleState.TEXT);
  339. m_ramManager.SetState(ModuleState.TEXT);
  340. m_audioManager.SetState(ModuleState.OFF);
  341. m_advancedData.SetState(ModuleState.OFF);
  342. break;
  343. case ModulePreset.FPS_FULL_RAM_TEXT:
  344. m_fpsManager.SetState(ModuleState.FULL);
  345. m_ramManager.SetState(ModuleState.TEXT);
  346. m_audioManager.SetState(ModuleState.OFF);
  347. m_advancedData.SetState(ModuleState.OFF);
  348. break;
  349. case ModulePreset.FPS_FULL_RAM_FULL:
  350. m_fpsManager.SetState(ModuleState.FULL);
  351. m_ramManager.SetState(ModuleState.FULL);
  352. m_audioManager.SetState(ModuleState.OFF);
  353. m_advancedData.SetState(ModuleState.OFF);
  354. break;
  355. case ModulePreset.FPS_TEXT_RAM_TEXT_AUDIO_TEXT:
  356. m_fpsManager.SetState(ModuleState.TEXT);
  357. m_ramManager.SetState(ModuleState.TEXT);
  358. m_audioManager.SetState(ModuleState.TEXT);
  359. m_advancedData.SetState(ModuleState.OFF);
  360. break;
  361. case ModulePreset.FPS_FULL_RAM_TEXT_AUDIO_TEXT:
  362. m_fpsManager.SetState(ModuleState.FULL);
  363. m_ramManager.SetState(ModuleState.TEXT);
  364. m_audioManager.SetState(ModuleState.TEXT);
  365. m_advancedData.SetState(ModuleState.OFF);
  366. break;
  367. case ModulePreset.FPS_FULL_RAM_FULL_AUDIO_TEXT:
  368. m_fpsManager.SetState(ModuleState.FULL);
  369. m_ramManager.SetState(ModuleState.FULL);
  370. m_audioManager.SetState(ModuleState.TEXT);
  371. m_advancedData.SetState(ModuleState.OFF);
  372. break;
  373. case ModulePreset.FPS_FULL_RAM_FULL_AUDIO_FULL:
  374. m_fpsManager.SetState(ModuleState.FULL);
  375. m_ramManager.SetState(ModuleState.FULL);
  376. m_audioManager.SetState(ModuleState.FULL);
  377. m_advancedData.SetState(ModuleState.OFF);
  378. break;
  379. case ModulePreset.FPS_FULL_RAM_FULL_AUDIO_FULL_ADVANCED_FULL:
  380. m_fpsManager.SetState(ModuleState.FULL);
  381. m_ramManager.SetState(ModuleState.FULL);
  382. m_audioManager.SetState(ModuleState.FULL);
  383. m_advancedData.SetState(ModuleState.FULL);
  384. break;
  385. case ModulePreset.FPS_BASIC_ADVANCED_FULL:
  386. m_fpsManager.SetState(ModuleState.BASIC);
  387. m_ramManager.SetState(ModuleState.OFF);
  388. m_audioManager.SetState(ModuleState.OFF);
  389. m_advancedData.SetState(ModuleState.FULL);
  390. break;
  391. default:
  392. //throw new ArgumentOutOfRangeException();
  393. break;
  394. }
  395. }
  396. public void ToggleActive()
  397. {
  398. if (!m_active)
  399. {
  400. Enable();
  401. }
  402. else
  403. {
  404. Disable();
  405. }
  406. }
  407. public void Enable()
  408. {
  409. m_fpsManager .RestorePreviousState();
  410. m_ramManager .RestorePreviousState();
  411. m_audioManager .RestorePreviousState();
  412. m_advancedData .RestorePreviousState();
  413. m_active = true;
  414. }
  415. public void Disable()
  416. {
  417. m_fpsManager .SetState(ModuleState.OFF);
  418. m_ramManager .SetState(ModuleState.OFF);
  419. m_audioManager .SetState(ModuleState.OFF);
  420. m_advancedData .SetState(ModuleState.OFF);
  421. m_active = false;
  422. }
  423. #endregion
  424. #region Methods -> Private
  425. private void Init()
  426. {
  427. if (m_keepAlive)
  428. {
  429. DontDestroyOnLoad(transform.root.gameObject);
  430. }
  431. m_fpsMonitor = GetComponentInChildren(typeof(G_FpsMonitor), true) as G_FpsMonitor;
  432. m_ramMonitor = GetComponentInChildren(typeof(G_RamMonitor), true) as G_RamMonitor;
  433. m_audioMonitor = GetComponentInChildren(typeof(G_AudioMonitor), true) as G_AudioMonitor;
  434. m_fpsManager = GetComponentInChildren(typeof(G_FpsManager), true) as G_FpsManager;
  435. m_ramManager = GetComponentInChildren(typeof(G_RamManager), true) as G_RamManager;
  436. m_audioManager = GetComponentInChildren(typeof(G_AudioManager), true) as G_AudioManager;
  437. m_advancedData = GetComponentInChildren(typeof(G_AdvancedData), true) as G_AdvancedData;
  438. m_fpsManager .SetPosition(m_graphModulePosition);
  439. m_ramManager .SetPosition(m_graphModulePosition);
  440. m_audioManager .SetPosition(m_graphModulePosition);
  441. m_advancedData .SetPosition(m_advancedModulePosition);
  442. m_fpsManager .SetState (m_fpsModuleState);
  443. m_ramManager .SetState (m_ramModuleState);
  444. m_audioManager .SetState (m_audioModuleState);
  445. m_advancedData .SetState (m_advancedModuleState);
  446. if (!m_enableOnStartup)
  447. {
  448. ToggleActive();
  449. }
  450. m_initialized = true;
  451. }
  452. private void CheckForHotkeyPresses()
  453. {
  454. // Toggle Mode ---------------------------------------
  455. if (m_toggleModeCtrl && m_toggleModeAlt)
  456. {
  457. if (CheckFor3KeyPress(m_toggleModeKeyCode, KeyCode.LeftControl, KeyCode.LeftAlt)
  458. || CheckFor3KeyPress(m_toggleModeKeyCode, KeyCode.RightControl, KeyCode.LeftAlt)
  459. || CheckFor3KeyPress(m_toggleModeKeyCode, KeyCode.RightControl, KeyCode.RightAlt)
  460. || CheckFor3KeyPress(m_toggleModeKeyCode, KeyCode.LeftControl, KeyCode.RightAlt))
  461. {
  462. ToggleModes();
  463. }
  464. }
  465. else if (m_toggleModeCtrl)
  466. {
  467. if ( CheckFor2KeyPress(m_toggleModeKeyCode, KeyCode.LeftControl)
  468. || CheckFor2KeyPress(m_toggleModeKeyCode, KeyCode.RightControl))
  469. {
  470. ToggleModes();
  471. }
  472. }
  473. else if (m_toggleModeAlt)
  474. {
  475. if ( CheckFor2KeyPress(m_toggleModeKeyCode, KeyCode.LeftAlt)
  476. || CheckFor2KeyPress(m_toggleModeKeyCode, KeyCode.RightAlt))
  477. {
  478. ToggleModes();
  479. }
  480. }
  481. else
  482. {
  483. if (CheckFor1KeyPress(m_toggleModeKeyCode))
  484. {
  485. ToggleModes();
  486. }
  487. }
  488. // Toggle Active ---------------------------------------
  489. if (m_toggleActiveCtrl && m_toggleActiveAlt)
  490. {
  491. if ( CheckFor3KeyPress(m_toggleActiveKeyCode, KeyCode.LeftControl, KeyCode.LeftAlt)
  492. || CheckFor3KeyPress(m_toggleActiveKeyCode, KeyCode.RightControl, KeyCode.LeftAlt)
  493. || CheckFor3KeyPress(m_toggleActiveKeyCode, KeyCode.RightControl, KeyCode.RightAlt)
  494. || CheckFor3KeyPress(m_toggleActiveKeyCode, KeyCode.LeftControl, KeyCode.RightAlt))
  495. {
  496. ToggleActive();
  497. }
  498. }
  499. else if (m_toggleActiveCtrl)
  500. {
  501. if ( CheckFor2KeyPress(m_toggleActiveKeyCode, KeyCode.LeftControl)
  502. || CheckFor2KeyPress(m_toggleActiveKeyCode, KeyCode.RightControl))
  503. {
  504. ToggleActive();
  505. }
  506. }
  507. else if (m_toggleActiveAlt)
  508. {
  509. if ( CheckFor2KeyPress(m_toggleActiveKeyCode, KeyCode.LeftAlt)
  510. || CheckFor2KeyPress(m_toggleActiveKeyCode, KeyCode.RightAlt))
  511. {
  512. ToggleActive();
  513. }
  514. }
  515. else
  516. {
  517. if (CheckFor1KeyPress(m_toggleActiveKeyCode))
  518. {
  519. ToggleActive();
  520. }
  521. }
  522. }
  523. private bool CheckFor1KeyPress(KeyCode key)
  524. {
  525. return Input.GetKeyDown(key);
  526. }
  527. private bool CheckFor2KeyPress(KeyCode key1, KeyCode key2)
  528. {
  529. return Input.GetKeyDown(key1) && Input.GetKey(key2)
  530. || Input.GetKeyDown(key2) && Input.GetKey(key1);
  531. }
  532. private bool CheckFor3KeyPress(KeyCode key1, KeyCode key2, KeyCode key3)
  533. {
  534. return Input.GetKeyDown(key1) && Input.GetKey(key2) && Input.GetKey(key3)
  535. || Input.GetKeyDown(key2) && Input.GetKey(key1) && Input.GetKey(key3)
  536. || Input.GetKeyDown(key3) && Input.GetKey(key1) && Input.GetKey(key2);
  537. }
  538. private void UpdateAllParameters()
  539. {
  540. m_fpsManager .UpdateParameters();
  541. m_ramManager .UpdateParameters();
  542. m_audioManager .UpdateParameters();
  543. m_advancedData .UpdateParameters();
  544. }
  545. private void RefreshAllParameters()
  546. {
  547. m_fpsManager .RefreshParameters();
  548. m_ramManager .RefreshParameters();
  549. m_audioManager .RefreshParameters();
  550. m_advancedData .RefreshParameters();
  551. }
  552. #endregion
  553. }
  554. }