| | 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 UnityEditor; |
| | 6 | | #if !UNITY_EDITOR |
| | 7 | | using UnityEngine; |
| | 8 | | #endif |
| | 9 | |
|
| | 10 | | namespace GDX.Developer.ConsoleCommands |
| | 11 | | { |
| | 12 | | #if UNITY_2022_2_OR_NEWER |
| | 13 | | public class QuitConsoleCommand : ConsoleCommandBase |
| | 14 | | { |
| | 15 | | int m_ErrorCode; |
| | 16 | |
|
| | 17 | | /// <inheritdoc /> |
| | 18 | | public override bool Evaluate(float deltaTime) |
| 0 | 19 | | { |
| 0 | 20 | | UnityEngine.Debug.Log($"Quitting! [{m_ErrorCode}]"); |
| | 21 | | #if UNITY_EDITOR |
| 0 | 22 | | EditorApplication.isPlaying = false; |
| | 23 | | #else |
| | 24 | | Application.Quit(m_ErrorCode); |
| | 25 | | #endif |
| 0 | 26 | | return true; |
| 0 | 27 | | } |
| | 28 | |
|
| | 29 | | /// <inheritdoc /> |
| | 30 | | public override Console.ConsoleAccessLevel GetAccessLevel() |
| 0 | 31 | | { |
| 0 | 32 | | return Console.ConsoleAccessLevel.Anonymous; |
| 0 | 33 | | } |
| | 34 | |
|
| | 35 | | /// <inheritdoc /> |
| | 36 | | public override string GetKeyword() |
| 7 | 37 | | { |
| 7 | 38 | | return "quit"; |
| 7 | 39 | | } |
| | 40 | |
|
| | 41 | | /// <inheritdoc /> |
| | 42 | | public override string GetHelpMessage() |
| 0 | 43 | | { |
| 0 | 44 | | return "Exits the application with the provided error code, if none is present will use the currently set on |
| 0 | 45 | | } |
| | 46 | |
|
| | 47 | | /// <inheritdoc /> |
| | 48 | | public override ConsoleCommandBase GetInstance(string context) |
| 0 | 49 | | { |
| 0 | 50 | | QuitConsoleCommand command = new QuitConsoleCommand(); |
| 0 | 51 | | if (string.IsNullOrEmpty(context)) |
| 0 | 52 | | { |
| 0 | 53 | | return command; |
| | 54 | | } |
| | 55 | |
|
| 0 | 56 | | int.TryParse(context, out int result); |
| 0 | 57 | | command.m_ErrorCode = result; |
| 0 | 58 | | return command; |
| 0 | 59 | | } |
| | 60 | | } |
| | 61 | | #endif // UNITY_2022_2_OR_NEWER |
| | 62 | | } |