| | 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 | | using UnityEngine; |
| | 7 | |
|
| | 8 | | namespace GDX.Developer.ConsoleCommands |
| | 9 | | { |
| | 10 | | #if UNITY_2022_2_OR_NEWER |
| | 11 | | public class WatchConsoleCommand : ConsoleCommandBase |
| | 12 | | { |
| | 13 | | string m_Identifier; |
| | 14 | | bool m_HasState; |
| | 15 | | bool m_DesiredState; |
| | 16 | |
|
| | 17 | | public override bool Evaluate(float deltaTime) |
| 0 | 18 | | { |
| 0 | 19 | | if (m_HasState) |
| 0 | 20 | | { |
| 0 | 21 | | WatchProvider.SetState(WatchProvider.GetWatch(m_Identifier), m_DesiredState); |
| 0 | 22 | | } |
| | 23 | | else |
| 0 | 24 | | { |
| 0 | 25 | | WatchProvider.ToggleState(WatchProvider.GetWatch(m_Identifier)); |
| 0 | 26 | | } |
| 0 | 27 | | return true; |
| 0 | 28 | | } |
| | 29 | |
|
| | 30 | | /// <inheritdoc /> |
| | 31 | | public override string GetKeyword() |
| 7 | 32 | | { |
| 7 | 33 | | return "watch"; |
| 7 | 34 | | } |
| | 35 | |
|
| | 36 | | /// <inheritdoc /> |
| | 37 | | public override string GetHelpUsage() |
| 0 | 38 | | { |
| 0 | 39 | | return "watch <identifier> [state]"; |
| 0 | 40 | | } |
| | 41 | |
|
| | 42 | | /// <inheritdoc /> |
| | 43 | | public override string GetHelpMessage() |
| 0 | 44 | | { |
| 0 | 45 | | return "Toggles the enabled/disabled state of a watch based on its unique identifier, or sets a specific sta |
| 0 | 46 | | } |
| | 47 | |
|
| | 48 | | /// <inheritdoc /> |
| | 49 | | public override ConsoleCommandBase GetInstance(string context) |
| 0 | 50 | | { |
| 0 | 51 | | if (string.IsNullOrEmpty(context)) |
| 0 | 52 | | { |
| 0 | 53 | | Debug.LogWarning("An identifier is required to find a watch."); |
| 0 | 54 | | return null; |
| | 55 | | } |
| | 56 | |
|
| 0 | 57 | | string[] split = context.Split(' ', StringSplitOptions.RemoveEmptyEntries); |
| | 58 | |
|
| 0 | 59 | | if (!WatchProvider.HasWatch(split[0])) |
| 0 | 60 | | { |
| 0 | 61 | | Debug.LogWarning($"Unable to find watch '{context}'."); |
| 0 | 62 | | return null; |
| | 63 | | } |
| | 64 | |
|
| 0 | 65 | | if (split.Length > 1) |
| 0 | 66 | | { |
| 0 | 67 | | return new WatchConsoleCommand |
| | 68 | | { |
| | 69 | | m_Identifier = split[0], m_DesiredState = split[1].IsBooleanPositiveValue(), m_HasState = true |
| | 70 | | }; |
| | 71 | | } |
| 0 | 72 | | return new WatchConsoleCommand { m_Identifier = split[0] }; |
| 0 | 73 | | } |
| | 74 | | } |
| | 75 | | #endif // UNITY_2022_2_OR_NEWER |
| | 76 | | } |