Settings.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Linq;
  5. using UnityEngine;
  6. namespace SRDebugger
  7. {
  8. public class Settings : ScriptableObject
  9. {
  10. public static Settings Instance
  11. {
  12. get
  13. {
  14. if (Settings._instance == null)
  15. {
  16. Settings._instance = Settings.GetOrCreateInstance();
  17. }
  18. if (Settings._instance._keyboardShortcuts != null && Settings._instance._keyboardShortcuts.Length > 0)
  19. {
  20. Settings._instance.UpgradeKeyboardShortcuts();
  21. }
  22. return Settings._instance;
  23. }
  24. }
  25. private static Settings.KeyboardShortcut[] GetDefaultKeyboardShortcuts()
  26. {
  27. return new Settings.KeyboardShortcut[]
  28. {
  29. new Settings.KeyboardShortcut
  30. {
  31. Control = true,
  32. Shift = true,
  33. Key = KeyCode.F1,
  34. Action = Settings.ShortcutActions.OpenSystemInfoTab
  35. },
  36. new Settings.KeyboardShortcut
  37. {
  38. Control = true,
  39. Shift = true,
  40. Key = KeyCode.F2,
  41. Action = Settings.ShortcutActions.OpenConsoleTab
  42. },
  43. new Settings.KeyboardShortcut
  44. {
  45. Control = true,
  46. Shift = true,
  47. Key = KeyCode.F3,
  48. Action = Settings.ShortcutActions.OpenOptionsTab
  49. },
  50. new Settings.KeyboardShortcut
  51. {
  52. Control = true,
  53. Shift = true,
  54. Key = KeyCode.F4,
  55. Action = Settings.ShortcutActions.OpenProfilerTab
  56. }
  57. };
  58. }
  59. private void UpgradeKeyboardShortcuts()
  60. {
  61. UnityEngine.Debug.Log("[SRDebugger] Upgrading Settings format");
  62. List<Settings.KeyboardShortcut> list = new List<Settings.KeyboardShortcut>();
  63. for (int i = 0; i < this._keyboardShortcuts.Length; i++)
  64. {
  65. Settings.KeyboardShortcut keyboardShortcut = this._keyboardShortcuts[i];
  66. list.Add(new Settings.KeyboardShortcut
  67. {
  68. Action = keyboardShortcut.Action,
  69. Key = keyboardShortcut.Key,
  70. Alt = this._keyboardModifierAlt,
  71. Shift = this._keyboardModifierShift,
  72. Control = this._keyboardModifierControl
  73. });
  74. }
  75. this._keyboardShortcuts = new Settings.KeyboardShortcut[0];
  76. this._newKeyboardShortcuts = list.ToArray();
  77. }
  78. public bool IsEnabled
  79. {
  80. get
  81. {
  82. return this._isEnabled;
  83. }
  84. }
  85. public bool AutoLoad
  86. {
  87. get
  88. {
  89. return this._autoLoad;
  90. }
  91. }
  92. public DefaultTabs DefaultTab
  93. {
  94. get
  95. {
  96. return this._defaultTab;
  97. }
  98. }
  99. public Settings.TriggerEnableModes EnableTrigger
  100. {
  101. get
  102. {
  103. return this._triggerEnableMode;
  104. }
  105. }
  106. public Settings.TriggerBehaviours TriggerBehaviour
  107. {
  108. get
  109. {
  110. return this._triggerBehaviour;
  111. }
  112. }
  113. public bool EnableKeyboardShortcuts
  114. {
  115. get
  116. {
  117. return this._enableKeyboardShortcuts;
  118. }
  119. }
  120. public IList<Settings.KeyboardShortcut> KeyboardShortcuts
  121. {
  122. get
  123. {
  124. return this._newKeyboardShortcuts;
  125. }
  126. }
  127. public bool KeyboardEscapeClose
  128. {
  129. get
  130. {
  131. return this._keyboardEscapeClose;
  132. }
  133. }
  134. public bool EnableBackgroundTransparency
  135. {
  136. get
  137. {
  138. return this._enableBackgroundTransparency;
  139. }
  140. }
  141. public bool RequireCode
  142. {
  143. get
  144. {
  145. return this._requireEntryCode;
  146. }
  147. }
  148. public bool RequireEntryCodeEveryTime
  149. {
  150. get
  151. {
  152. return this._requireEntryCodeEveryTime;
  153. }
  154. }
  155. public IList<int> EntryCode
  156. {
  157. get
  158. {
  159. return new ReadOnlyCollection<int>(this._entryCode);
  160. }
  161. set
  162. {
  163. if (value.Count != 4)
  164. {
  165. throw new Exception("Entry code must be length 4");
  166. }
  167. if (value.Any((int p) => p > 9 || p < 0))
  168. {
  169. throw new Exception("All digits in entry code must be >= 0 and <= 9");
  170. }
  171. this._entryCode = value.ToArray<int>();
  172. }
  173. }
  174. public bool UseDebugCamera
  175. {
  176. get
  177. {
  178. return this._useDebugCamera;
  179. }
  180. }
  181. public int DebugLayer
  182. {
  183. get
  184. {
  185. return this._debugLayer;
  186. }
  187. }
  188. public float DebugCameraDepth
  189. {
  190. get
  191. {
  192. return this._debugCameraDepth;
  193. }
  194. }
  195. public bool CollapseDuplicateLogEntries
  196. {
  197. get
  198. {
  199. return this._collapseDuplicateLogEntries;
  200. }
  201. }
  202. public bool RichTextInConsole
  203. {
  204. get
  205. {
  206. return this._richTextInConsole;
  207. }
  208. }
  209. public string ApiKey
  210. {
  211. get
  212. {
  213. return this._apiKey;
  214. }
  215. }
  216. public bool EnableBugReporter
  217. {
  218. get
  219. {
  220. return this._enableBugReporter;
  221. }
  222. }
  223. public IList<DefaultTabs> DisabledTabs
  224. {
  225. get
  226. {
  227. return this._disabledTabs;
  228. }
  229. }
  230. public PinAlignment TriggerPosition
  231. {
  232. get
  233. {
  234. return this._triggerPosition;
  235. }
  236. }
  237. public PinAlignment ProfilerAlignment
  238. {
  239. get
  240. {
  241. return this._profilerAlignment;
  242. }
  243. }
  244. public PinAlignment OptionsAlignment
  245. {
  246. get
  247. {
  248. return this._optionsAlignment;
  249. }
  250. }
  251. public ConsoleAlignment ConsoleAlignment
  252. {
  253. get
  254. {
  255. return this._consoleAlignment;
  256. }
  257. set
  258. {
  259. this._consoleAlignment = value;
  260. }
  261. }
  262. public int MaximumConsoleEntries
  263. {
  264. get
  265. {
  266. return this._maximumConsoleEntries;
  267. }
  268. set
  269. {
  270. this._maximumConsoleEntries = value;
  271. }
  272. }
  273. public bool EnableEventSystemGeneration
  274. {
  275. get
  276. {
  277. return this._enableEventSystemCreation;
  278. }
  279. set
  280. {
  281. this._enableEventSystemCreation = value;
  282. }
  283. }
  284. public bool AutomaticallyShowCursor
  285. {
  286. get
  287. {
  288. return this._automaticShowCursor;
  289. }
  290. }
  291. private static Settings GetOrCreateInstance()
  292. {
  293. Settings settings = Resources.Load<Settings>("SRDebugger/Settings");
  294. if (settings == null)
  295. {
  296. settings = ScriptableObject.CreateInstance<Settings>();
  297. }
  298. return settings;
  299. }
  300. private const string ResourcesPath = "/usr/Resources/SRDebugger";
  301. private const string ResourcesName = "Settings";
  302. private static Settings _instance;
  303. [SerializeField]
  304. private bool _isEnabled = true;
  305. [SerializeField]
  306. private bool _autoLoad = true;
  307. [SerializeField]
  308. private DefaultTabs _defaultTab;
  309. [SerializeField]
  310. private Settings.TriggerEnableModes _triggerEnableMode;
  311. [SerializeField]
  312. private Settings.TriggerBehaviours _triggerBehaviour;
  313. [SerializeField]
  314. private bool _enableKeyboardShortcuts = true;
  315. [SerializeField]
  316. private Settings.KeyboardShortcut[] _keyboardShortcuts;
  317. [SerializeField]
  318. private Settings.KeyboardShortcut[] _newKeyboardShortcuts = Settings.GetDefaultKeyboardShortcuts();
  319. [SerializeField]
  320. private bool _keyboardModifierControl = true;
  321. [SerializeField]
  322. private bool _keyboardModifierAlt;
  323. [SerializeField]
  324. private bool _keyboardModifierShift = true;
  325. [SerializeField]
  326. private bool _keyboardEscapeClose = true;
  327. [SerializeField]
  328. private bool _enableBackgroundTransparency = true;
  329. [SerializeField]
  330. private bool _collapseDuplicateLogEntries = true;
  331. [SerializeField]
  332. private bool _richTextInConsole = true;
  333. [SerializeField]
  334. private bool _requireEntryCode;
  335. [SerializeField]
  336. private bool _requireEntryCodeEveryTime;
  337. [SerializeField]
  338. private int[] _entryCode = new int[4];
  339. [SerializeField]
  340. private bool _useDebugCamera;
  341. [SerializeField]
  342. private int _debugLayer = 5;
  343. [Range(-100f, 100f)]
  344. [SerializeField]
  345. private float _debugCameraDepth = 100f;
  346. [SerializeField]
  347. private string _apiKey = string.Empty;
  348. [SerializeField]
  349. private bool _enableBugReporter;
  350. [SerializeField]
  351. private DefaultTabs[] _disabledTabs = new DefaultTabs[0];
  352. [SerializeField]
  353. private PinAlignment _profilerAlignment = PinAlignment.BottomLeft;
  354. [SerializeField]
  355. private PinAlignment _optionsAlignment = PinAlignment.BottomRight;
  356. [SerializeField]
  357. private ConsoleAlignment _consoleAlignment;
  358. [SerializeField]
  359. private PinAlignment _triggerPosition;
  360. [SerializeField]
  361. private int _maximumConsoleEntries = 1500;
  362. [SerializeField]
  363. private bool _enableEventSystemCreation = true;
  364. [SerializeField]
  365. private bool _automaticShowCursor = true;
  366. public enum ShortcutActions
  367. {
  368. None,
  369. OpenSystemInfoTab,
  370. OpenConsoleTab,
  371. OpenOptionsTab,
  372. OpenProfilerTab,
  373. OpenBugReporterTab,
  374. ClosePanel,
  375. OpenPanel,
  376. TogglePanel,
  377. ShowBugReportPopover,
  378. ToggleDockedConsole,
  379. ToggleDockedProfiler
  380. }
  381. public enum TriggerBehaviours
  382. {
  383. TripleTap,
  384. TapAndHold,
  385. DoubleTap
  386. }
  387. public enum TriggerEnableModes
  388. {
  389. Enabled,
  390. MobileOnly,
  391. Off,
  392. DevelopmentBuildsOnly
  393. }
  394. [Serializable]
  395. public sealed class KeyboardShortcut
  396. {
  397. [SerializeField]
  398. public Settings.ShortcutActions Action;
  399. [SerializeField]
  400. public bool Alt;
  401. [SerializeField]
  402. public bool Control;
  403. [SerializeField]
  404. public KeyCode Key;
  405. [SerializeField]
  406. public bool Shift;
  407. }
  408. }
  409. }