GraphyManager.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  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. // We need to enable this on startup because we disable it in GraphyManagerEditor
  450. GetComponent<Canvas>().enabled = true;
  451. }
  452. m_initialized = true;
  453. }
  454. private void CheckForHotkeyPresses()
  455. {
  456. // Toggle Mode ---------------------------------------
  457. if (m_toggleModeCtrl && m_toggleModeAlt)
  458. {
  459. if (CheckFor3KeyPress(m_toggleModeKeyCode, KeyCode.LeftControl, KeyCode.LeftAlt)
  460. || CheckFor3KeyPress(m_toggleModeKeyCode, KeyCode.RightControl, KeyCode.LeftAlt)
  461. || CheckFor3KeyPress(m_toggleModeKeyCode, KeyCode.RightControl, KeyCode.RightAlt)
  462. || CheckFor3KeyPress(m_toggleModeKeyCode, KeyCode.LeftControl, KeyCode.RightAlt))
  463. {
  464. ToggleModes();
  465. }
  466. }
  467. else if (m_toggleModeCtrl)
  468. {
  469. if ( CheckFor2KeyPress(m_toggleModeKeyCode, KeyCode.LeftControl)
  470. || CheckFor2KeyPress(m_toggleModeKeyCode, KeyCode.RightControl))
  471. {
  472. ToggleModes();
  473. }
  474. }
  475. else if (m_toggleModeAlt)
  476. {
  477. if ( CheckFor2KeyPress(m_toggleModeKeyCode, KeyCode.LeftAlt)
  478. || CheckFor2KeyPress(m_toggleModeKeyCode, KeyCode.RightAlt))
  479. {
  480. ToggleModes();
  481. }
  482. }
  483. else
  484. {
  485. if (CheckFor1KeyPress(m_toggleModeKeyCode))
  486. {
  487. ToggleModes();
  488. }
  489. }
  490. // Toggle Active ---------------------------------------
  491. if (m_toggleActiveCtrl && m_toggleActiveAlt)
  492. {
  493. if ( CheckFor3KeyPress(m_toggleActiveKeyCode, KeyCode.LeftControl, KeyCode.LeftAlt)
  494. || CheckFor3KeyPress(m_toggleActiveKeyCode, KeyCode.RightControl, KeyCode.LeftAlt)
  495. || CheckFor3KeyPress(m_toggleActiveKeyCode, KeyCode.RightControl, KeyCode.RightAlt)
  496. || CheckFor3KeyPress(m_toggleActiveKeyCode, KeyCode.LeftControl, KeyCode.RightAlt))
  497. {
  498. ToggleActive();
  499. }
  500. }
  501. else if (m_toggleActiveCtrl)
  502. {
  503. if ( CheckFor2KeyPress(m_toggleActiveKeyCode, KeyCode.LeftControl)
  504. || CheckFor2KeyPress(m_toggleActiveKeyCode, KeyCode.RightControl))
  505. {
  506. ToggleActive();
  507. }
  508. }
  509. else if (m_toggleActiveAlt)
  510. {
  511. if ( CheckFor2KeyPress(m_toggleActiveKeyCode, KeyCode.LeftAlt)
  512. || CheckFor2KeyPress(m_toggleActiveKeyCode, KeyCode.RightAlt))
  513. {
  514. ToggleActive();
  515. }
  516. }
  517. else
  518. {
  519. if (CheckFor1KeyPress(m_toggleActiveKeyCode))
  520. {
  521. ToggleActive();
  522. }
  523. }
  524. }
  525. private bool CheckFor1KeyPress(KeyCode key)
  526. {
  527. return Input.GetKeyDown(key);
  528. }
  529. private bool CheckFor2KeyPress(KeyCode key1, KeyCode key2)
  530. {
  531. return Input.GetKeyDown(key1) && Input.GetKey(key2)
  532. || Input.GetKeyDown(key2) && Input.GetKey(key1);
  533. }
  534. private bool CheckFor3KeyPress(KeyCode key1, KeyCode key2, KeyCode key3)
  535. {
  536. return Input.GetKeyDown(key1) && Input.GetKey(key2) && Input.GetKey(key3)
  537. || Input.GetKeyDown(key2) && Input.GetKey(key1) && Input.GetKey(key3)
  538. || Input.GetKeyDown(key3) && Input.GetKey(key1) && Input.GetKey(key2);
  539. }
  540. private void UpdateAllParameters()
  541. {
  542. m_fpsManager .UpdateParameters();
  543. m_ramManager .UpdateParameters();
  544. m_audioManager .UpdateParameters();
  545. m_advancedData .UpdateParameters();
  546. }
  547. private void RefreshAllParameters()
  548. {
  549. m_fpsManager .RefreshParameters();
  550. m_ramManager .RefreshParameters();
  551. m_audioManager .RefreshParameters();
  552. m_advancedData .RefreshParameters();
  553. }
  554. #endregion
  555. }
  556. }