123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482 |
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using UnityEngine;
- namespace SRDebugger
- {
- public class Settings : ScriptableObject
- {
- public static Settings Instance
- {
- get
- {
- if (Settings._instance == null)
- {
- Settings._instance = Settings.GetOrCreateInstance();
- }
- if (Settings._instance._keyboardShortcuts != null && Settings._instance._keyboardShortcuts.Length > 0)
- {
- Settings._instance.UpgradeKeyboardShortcuts();
- }
- return Settings._instance;
- }
- }
- private static Settings.KeyboardShortcut[] GetDefaultKeyboardShortcuts()
- {
- return new Settings.KeyboardShortcut[]
- {
- new Settings.KeyboardShortcut
- {
- Control = true,
- Shift = true,
- Key = KeyCode.F1,
- Action = Settings.ShortcutActions.OpenSystemInfoTab
- },
- new Settings.KeyboardShortcut
- {
- Control = true,
- Shift = true,
- Key = KeyCode.F2,
- Action = Settings.ShortcutActions.OpenConsoleTab
- },
- new Settings.KeyboardShortcut
- {
- Control = true,
- Shift = true,
- Key = KeyCode.F3,
- Action = Settings.ShortcutActions.OpenOptionsTab
- },
- new Settings.KeyboardShortcut
- {
- Control = true,
- Shift = true,
- Key = KeyCode.F4,
- Action = Settings.ShortcutActions.OpenProfilerTab
- }
- };
- }
- private void UpgradeKeyboardShortcuts()
- {
- UnityEngine.Debug.Log("[SRDebugger] Upgrading Settings format");
- List<Settings.KeyboardShortcut> list = new List<Settings.KeyboardShortcut>();
- for (int i = 0; i < this._keyboardShortcuts.Length; i++)
- {
- Settings.KeyboardShortcut keyboardShortcut = this._keyboardShortcuts[i];
- list.Add(new Settings.KeyboardShortcut
- {
- Action = keyboardShortcut.Action,
- Key = keyboardShortcut.Key,
- Alt = this._keyboardModifierAlt,
- Shift = this._keyboardModifierShift,
- Control = this._keyboardModifierControl
- });
- }
- this._keyboardShortcuts = new Settings.KeyboardShortcut[0];
- this._newKeyboardShortcuts = list.ToArray();
- }
- public bool IsEnabled
- {
- get
- {
- return this._isEnabled;
- }
- }
- public bool AutoLoad
- {
- get
- {
- return this._autoLoad;
- }
- }
- public DefaultTabs DefaultTab
- {
- get
- {
- return this._defaultTab;
- }
- }
- public Settings.TriggerEnableModes EnableTrigger
- {
- get
- {
- return this._triggerEnableMode;
- }
- }
- public Settings.TriggerBehaviours TriggerBehaviour
- {
- get
- {
- return this._triggerBehaviour;
- }
- }
- public bool EnableKeyboardShortcuts
- {
- get
- {
- return this._enableKeyboardShortcuts;
- }
- }
- public IList<Settings.KeyboardShortcut> KeyboardShortcuts
- {
- get
- {
- return this._newKeyboardShortcuts;
- }
- }
- public bool KeyboardEscapeClose
- {
- get
- {
- return this._keyboardEscapeClose;
- }
- }
- public bool EnableBackgroundTransparency
- {
- get
- {
- return this._enableBackgroundTransparency;
- }
- }
- public bool RequireCode
- {
- get
- {
- return this._requireEntryCode;
- }
- }
- public bool RequireEntryCodeEveryTime
- {
- get
- {
- return this._requireEntryCodeEveryTime;
- }
- }
- public IList<int> EntryCode
- {
- get
- {
- return new ReadOnlyCollection<int>(this._entryCode);
- }
- set
- {
- if (value.Count != 4)
- {
- throw new Exception("Entry code must be length 4");
- }
- if (value.Any((int p) => p > 9 || p < 0))
- {
- throw new Exception("All digits in entry code must be >= 0 and <= 9");
- }
- this._entryCode = value.ToArray<int>();
- }
- }
- public bool UseDebugCamera
- {
- get
- {
- return this._useDebugCamera;
- }
- }
- public int DebugLayer
- {
- get
- {
- return this._debugLayer;
- }
- }
- public float DebugCameraDepth
- {
- get
- {
- return this._debugCameraDepth;
- }
- }
- public bool CollapseDuplicateLogEntries
- {
- get
- {
- return this._collapseDuplicateLogEntries;
- }
- }
- public bool RichTextInConsole
- {
- get
- {
- return this._richTextInConsole;
- }
- }
- public string ApiKey
- {
- get
- {
- return this._apiKey;
- }
- }
- public bool EnableBugReporter
- {
- get
- {
- return this._enableBugReporter;
- }
- }
- public IList<DefaultTabs> DisabledTabs
- {
- get
- {
- return this._disabledTabs;
- }
- }
- public PinAlignment TriggerPosition
- {
- get
- {
- return this._triggerPosition;
- }
- }
- public PinAlignment ProfilerAlignment
- {
- get
- {
- return this._profilerAlignment;
- }
- }
- public PinAlignment OptionsAlignment
- {
- get
- {
- return this._optionsAlignment;
- }
- }
- public ConsoleAlignment ConsoleAlignment
- {
- get
- {
- return this._consoleAlignment;
- }
- set
- {
- this._consoleAlignment = value;
- }
- }
- public int MaximumConsoleEntries
- {
- get
- {
- return this._maximumConsoleEntries;
- }
- set
- {
- this._maximumConsoleEntries = value;
- }
- }
- public bool EnableEventSystemGeneration
- {
- get
- {
- return this._enableEventSystemCreation;
- }
- set
- {
- this._enableEventSystemCreation = value;
- }
- }
- public bool AutomaticallyShowCursor
- {
- get
- {
- return this._automaticShowCursor;
- }
- }
- private static Settings GetOrCreateInstance()
- {
- Settings settings = Resources.Load<Settings>("SRDebugger/Settings");
- if (settings == null)
- {
- settings = ScriptableObject.CreateInstance<Settings>();
- }
- return settings;
- }
- private const string ResourcesPath = "/usr/Resources/SRDebugger";
- private const string ResourcesName = "Settings";
- private static Settings _instance;
- [SerializeField]
- private bool _isEnabled = true;
- [SerializeField]
- private bool _autoLoad = true;
- [SerializeField]
- private DefaultTabs _defaultTab;
- [SerializeField]
- private Settings.TriggerEnableModes _triggerEnableMode;
- [SerializeField]
- private Settings.TriggerBehaviours _triggerBehaviour;
- [SerializeField]
- private bool _enableKeyboardShortcuts = true;
- [SerializeField]
- private Settings.KeyboardShortcut[] _keyboardShortcuts;
- [SerializeField]
- private Settings.KeyboardShortcut[] _newKeyboardShortcuts = Settings.GetDefaultKeyboardShortcuts();
- [SerializeField]
- private bool _keyboardModifierControl = true;
- [SerializeField]
- private bool _keyboardModifierAlt;
- [SerializeField]
- private bool _keyboardModifierShift = true;
- [SerializeField]
- private bool _keyboardEscapeClose = true;
- [SerializeField]
- private bool _enableBackgroundTransparency = true;
- [SerializeField]
- private bool _collapseDuplicateLogEntries = true;
- [SerializeField]
- private bool _richTextInConsole = true;
- [SerializeField]
- private bool _requireEntryCode;
- [SerializeField]
- private bool _requireEntryCodeEveryTime;
- [SerializeField]
- private int[] _entryCode = new int[4];
- [SerializeField]
- private bool _useDebugCamera;
- [SerializeField]
- private int _debugLayer = 5;
- [Range(-100f, 100f)]
- [SerializeField]
- private float _debugCameraDepth = 100f;
- [SerializeField]
- private string _apiKey = string.Empty;
- [SerializeField]
- private bool _enableBugReporter;
- [SerializeField]
- private DefaultTabs[] _disabledTabs = new DefaultTabs[0];
- [SerializeField]
- private PinAlignment _profilerAlignment = PinAlignment.BottomLeft;
- [SerializeField]
- private PinAlignment _optionsAlignment = PinAlignment.BottomRight;
- [SerializeField]
- private ConsoleAlignment _consoleAlignment;
- [SerializeField]
- private PinAlignment _triggerPosition;
- [SerializeField]
- private int _maximumConsoleEntries = 1500;
- [SerializeField]
- private bool _enableEventSystemCreation = true;
- [SerializeField]
- private bool _automaticShowCursor = true;
- public enum ShortcutActions
- {
- None,
- OpenSystemInfoTab,
- OpenConsoleTab,
- OpenOptionsTab,
- OpenProfilerTab,
- OpenBugReporterTab,
- ClosePanel,
- OpenPanel,
- TogglePanel,
- ShowBugReportPopover,
- ToggleDockedConsole,
- ToggleDockedProfiler
- }
- public enum TriggerBehaviours
- {
- TripleTap,
- TapAndHold,
- DoubleTap
- }
- public enum TriggerEnableModes
- {
- Enabled,
- MobileOnly,
- Off,
- DevelopmentBuildsOnly
- }
- [Serializable]
- public sealed class KeyboardShortcut
- {
- [SerializeField]
- public Settings.ShortcutActions Action;
- [SerializeField]
- public bool Alt;
- [SerializeField]
- public bool Control;
- [SerializeField]
- public KeyCode Key;
- [SerializeField]
- public bool Shift;
- }
- }
- }
|