| | 1 | | // Copyright (c) 2020-2022 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.Collections.Generic; |
| | 6 | |
|
| | 7 | | namespace GDX.Developer.ConsoleCommands |
| | 8 | | { |
| | 9 | | #if UNITY_2022_2_OR_NEWER |
| | 10 | | public class HelpConsoleCommand : ConsoleCommandBase |
| | 11 | | { |
| | 12 | | /// <inheritdoc /> |
| | 13 | | public override bool Evaluate(float deltaTime) |
| 0 | 14 | | { |
| 0 | 15 | | TextGenerator textGenerator = new TextGenerator(); |
| 0 | 16 | | List<string> sortedCommands = new List<string>(Console.GetCommandKeywordsCopy()); |
| 0 | 17 | | sortedCommands.Sort(); |
| 0 | 18 | | int commandCount = sortedCommands.Count; |
| 0 | 19 | | Console.ConsoleAccessLevel maxAccessLevel = Console.GetAccessLevel(); |
| 0 | 20 | | for (int i = 0; i < commandCount; i++) |
| 0 | 21 | | { |
| 0 | 22 | | ConsoleCommandBase command = Console.GetCommand(sortedCommands[i]); |
| | 23 | |
|
| | 24 | | // Dont show commands that are not usable. |
| 0 | 25 | | if (command.GetAccessLevel() > maxAccessLevel) |
| 0 | 26 | | { |
| 0 | 27 | | continue; |
| | 28 | | } |
| | 29 | |
|
| 0 | 30 | | textGenerator.AppendLine(command.GetHelpUsage()); |
| 0 | 31 | | textGenerator.Append($"\t{command.GetHelpMessage()}"); |
| 0 | 32 | | if (command.IsEditorOnly()) |
| 0 | 33 | | { |
| 0 | 34 | | textGenerator.AppendLine("(Editor Only)"); |
| 0 | 35 | | } |
| | 36 | | else |
| 0 | 37 | | { |
| 0 | 38 | | textGenerator.AppendLine(); |
| 0 | 39 | | } |
| 0 | 40 | | } |
| | 41 | |
|
| 0 | 42 | | UnityEngine.Debug.Log(textGenerator.ToString()); |
| 0 | 43 | | return true; |
| 0 | 44 | | } |
| | 45 | |
|
| | 46 | | /// <inheritdoc /> |
| | 47 | | public override Console.ConsoleAccessLevel GetAccessLevel() |
| 0 | 48 | | { |
| 0 | 49 | | return Console.ConsoleAccessLevel.Anonymous; |
| 0 | 50 | | } |
| | 51 | |
|
| | 52 | | /// <inheritdoc /> |
| | 53 | | public override string GetKeyword() |
| 7 | 54 | | { |
| 7 | 55 | | return "help"; |
| 7 | 56 | | } |
| | 57 | |
|
| | 58 | | /// <inheritdoc /> |
| | 59 | | public override string GetHelpMessage() |
| 0 | 60 | | { |
| 0 | 61 | | return "Display a list of all known commands and their usage."; |
| 0 | 62 | | } |
| | 63 | | } |
| | 64 | | #endif // UNITY_2022_2_OR_NEWER |
| | 65 | | } |