| | 1 | | // Copyright (c) 2020-2024 dotBunny Inc. |
| | 2 | | // dotBunny licenses this file to you under the BSL-1.0 license. |
| | 3 | | // See the LICENSE file in the project root for more information. |
| | 4 | |
|
| | 5 | | using System; |
| | 6 | |
|
| | 7 | | namespace GDX.Developer |
| | 8 | | { |
| | 9 | | #if UNITY_2022_2_OR_NEWER |
| | 10 | | public abstract class ConsoleVariableBase |
| | 11 | | { |
| | 12 | | public enum ConsoleVariableType |
| | 13 | | { |
| | 14 | | String, |
| | 15 | | Integer, |
| | 16 | | Float, |
| | 17 | | Boolean |
| | 18 | | } |
| | 19 | |
|
| | 20 | | [Flags] |
| | 21 | | public enum ConsoleVariableFlags |
| | 22 | | { |
| | 23 | | None = 0x0, |
| | 24 | | Setting = 0x1, |
| | 25 | | Cheat = 0x2 |
| | 26 | | } |
| | 27 | |
|
| | 28 | | readonly ConsoleVariableFlags m_Flags; |
| | 29 | | readonly string m_Name; |
| | 30 | | readonly string m_Description; |
| | 31 | |
|
| | 32 | | /// <summary> |
| | 33 | | /// Returns the minimum access level required to set a variable. |
| | 34 | | /// </summary> |
| | 35 | | /// <remarks>Overrideable, but defaults to having user level access.</remarks> |
| | 36 | | /// <returns>The required user access level to alter a variable.</returns> |
| | 37 | | public virtual Console.ConsoleAccessLevel GetAccessLevel() |
| 0 | 38 | | { |
| 0 | 39 | | return Console.ConsoleAccessLevel.Anonymous; |
| 0 | 40 | | } |
| | 41 | |
|
| | 42 | | public abstract ConsoleVariableType GetConsoleVariableType(); |
| | 43 | | public abstract object GetBoxedValue(); |
| | 44 | | public abstract void SetValueFromString(string newValue); |
| | 45 | | public abstract string GetCurrentValueAsString(); |
| | 46 | | public abstract string GetDefaultValueAsString(); |
| | 47 | |
|
| 0 | 48 | | protected ConsoleVariableBase(string name, string description, ConsoleVariableFlags flags) |
| 0 | 49 | | { |
| 0 | 50 | | m_Name = name; |
| 0 | 51 | | m_Description = description; |
| 0 | 52 | | m_Flags = flags; |
| | 53 | |
|
| 0 | 54 | | Console.RegisterVariable(this); |
| 0 | 55 | | } |
| | 56 | |
|
| | 57 | | public virtual string[] GetArgumentAutoCompleteSuggestions(string hint, string[] existingSet = null) |
| 0 | 58 | | { |
| 0 | 59 | | string defaultValue = GetDefaultValueAsString(); |
| 0 | 60 | | if (hint == defaultValue) return null; |
| 0 | 61 | | return new string[] { defaultValue }; |
| 0 | 62 | | } |
| | 63 | |
|
| | 64 | | public string GetName() |
| 0 | 65 | | { |
| 0 | 66 | | return m_Name; |
| 0 | 67 | | } |
| | 68 | |
|
| | 69 | | public string GetDescription() |
| 0 | 70 | | { |
| 0 | 71 | | return m_Description; |
| 0 | 72 | | } |
| | 73 | |
|
| | 74 | | public ConsoleVariableFlags GetFlags() |
| 0 | 75 | | { |
| 0 | 76 | | return m_Flags; |
| 0 | 77 | | } |
| | 78 | | } |
| | 79 | | #endif // UNITY_2022_2_OR_NEWER |
| | 80 | | } |