| | 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.ConsoleVariables |
| | 8 | | { |
| | 9 | | #if UNITY_2022_2_OR_NEWER |
| | 10 | | public class StringConsoleVariable : ConsoleVariableBase |
| | 11 | | { |
| | 12 | | public Action<string> OnValueChanged; |
| | 13 | | readonly string m_DefaultValue; |
| | 14 | | string m_CurrentValue; |
| | 15 | |
|
| | 16 | | public StringConsoleVariable(string name, string description, string defaultValue, |
| 0 | 17 | | ConsoleVariableFlags flags = ConsoleVariableFlags.None) : base(name, description, flags) |
| 0 | 18 | | { |
| 0 | 19 | | m_DefaultValue = ConsoleVariableSettings.TryGetValue(name, out string settingsValue) ? settingsValue : defau |
| 0 | 20 | | m_CurrentValue = CommandLineParser.Arguments.ContainsKey(name) ? CommandLineParser.Arguments[name] : default |
| 0 | 21 | | } |
| | 22 | |
|
| | 23 | | /// <inheritdoc /> |
| | 24 | | public override ConsoleVariableType GetConsoleVariableType() |
| 0 | 25 | | { |
| 0 | 26 | | return ConsoleVariableType.String; |
| 0 | 27 | | } |
| | 28 | |
|
| | 29 | | /// <inheritdoc /> |
| | 30 | | public override object GetBoxedValue() |
| 0 | 31 | | { |
| 0 | 32 | | return m_CurrentValue; |
| 0 | 33 | | } |
| | 34 | |
|
| | 35 | | /// <inheritdoc /> |
| | 36 | | public sealed override void SetValueFromString(string newValue) |
| 0 | 37 | | { |
| 0 | 38 | | m_CurrentValue = newValue; |
| 0 | 39 | | OnValueChanged?.Invoke(m_CurrentValue); |
| 0 | 40 | | } |
| | 41 | |
|
| | 42 | | /// <inheritdoc /> |
| | 43 | | public override string GetCurrentValueAsString() |
| 0 | 44 | | { |
| 0 | 45 | | return m_CurrentValue; |
| 0 | 46 | | } |
| | 47 | |
|
| | 48 | | /// <inheritdoc /> |
| | 49 | | public override string GetDefaultValueAsString() |
| 0 | 50 | | { |
| 0 | 51 | | return m_DefaultValue; |
| 0 | 52 | | } |
| | 53 | |
|
| | 54 | | public string GetValue() |
| 0 | 55 | | { |
| 0 | 56 | | return m_CurrentValue; |
| 0 | 57 | | } |
| | 58 | |
|
| | 59 | | public void SetValue(string newValue) |
| 0 | 60 | | { |
| 0 | 61 | | m_CurrentValue = newValue; |
| 0 | 62 | | OnValueChanged?.Invoke(m_CurrentValue); |
| 0 | 63 | | } |
| | 64 | | } |
| | 65 | | #endif // UNITY_2022_2_OR_NEWER |
| | 66 | | } |