| | | 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 IntegerConsoleVariable : ConsoleVariableBase |
| | | 11 | | { |
| | | 12 | | public Action<int> OnValueChanged; |
| | | 13 | | readonly int m_DefaultValue; |
| | | 14 | | int m_CurrentValue; |
| | | 15 | | |
| | | 16 | | public IntegerConsoleVariable(string name, string description, int defaultValue, |
| | 0 | 17 | | ConsoleVariableFlags flags = ConsoleVariableFlags.None) : base(name, description, flags) |
| | 0 | 18 | | { |
| | 0 | 19 | | if (ConsoleVariableSettings.TryGetValue(name, out string settingsValue) && int.TryParse(settingsValue, out i |
| | 0 | 20 | | { |
| | 0 | 21 | | m_DefaultValue = newDefaultValue; |
| | 0 | 22 | | } |
| | | 23 | | else |
| | 0 | 24 | | { |
| | 0 | 25 | | m_DefaultValue = defaultValue; |
| | 0 | 26 | | } |
| | | 27 | | |
| | 0 | 28 | | if (CommandLineParser.Arguments.ContainsKey(name) && int.TryParse(CommandLineParser.Arguments[name], out int |
| | 0 | 29 | | { |
| | 0 | 30 | | m_CurrentValue = newCurrentValue; |
| | 0 | 31 | | } |
| | | 32 | | else |
| | 0 | 33 | | { |
| | 0 | 34 | | m_CurrentValue = defaultValue; |
| | 0 | 35 | | } |
| | 0 | 36 | | } |
| | | 37 | | |
| | | 38 | | /// <inheritdoc /> |
| | | 39 | | public override ConsoleVariableType GetConsoleVariableType() |
| | 0 | 40 | | { |
| | 0 | 41 | | return ConsoleVariableType.Integer; |
| | 0 | 42 | | } |
| | | 43 | | |
| | | 44 | | /// <inheritdoc /> |
| | | 45 | | public override object GetBoxedValue() |
| | 0 | 46 | | { |
| | 0 | 47 | | return m_CurrentValue; |
| | 0 | 48 | | } |
| | | 49 | | |
| | | 50 | | /// <inheritdoc /> |
| | | 51 | | public sealed override void SetValueFromString(string newValue) |
| | 0 | 52 | | { |
| | 0 | 53 | | if (int.TryParse(newValue, out m_CurrentValue)) |
| | 0 | 54 | | { |
| | 0 | 55 | | OnValueChanged?.Invoke(m_CurrentValue); |
| | 0 | 56 | | } |
| | 0 | 57 | | } |
| | | 58 | | |
| | | 59 | | /// <inheritdoc /> |
| | | 60 | | public override string GetCurrentValueAsString() |
| | 0 | 61 | | { |
| | 0 | 62 | | return m_CurrentValue.ToString(); |
| | 0 | 63 | | } |
| | | 64 | | |
| | | 65 | | /// <inheritdoc /> |
| | | 66 | | public override string GetDefaultValueAsString() |
| | 0 | 67 | | { |
| | 0 | 68 | | return m_DefaultValue.ToString(); |
| | 0 | 69 | | } |
| | | 70 | | |
| | | 71 | | public int GetValue() |
| | 0 | 72 | | { |
| | 0 | 73 | | return m_CurrentValue; |
| | 0 | 74 | | } |
| | | 75 | | |
| | | 76 | | public void SetValue(int newValue) |
| | 0 | 77 | | { |
| | 0 | 78 | | m_CurrentValue = newValue; |
| | 0 | 79 | | OnValueChanged?.Invoke(m_CurrentValue); |
| | 0 | 80 | | } |
| | | 81 | | } |
| | | 82 | | #endif // UNITY_2022_2_OR_NEWER |
| | | 83 | | } |