using System; namespace UnityConsole { public static class ConsoleCommandHelpers { public static ConsoleCommandResult ExtractBool( Action action, params string[] args) { if (args.Length != 1) { return ConsoleCommandResult.Failed("Expecting 1 argument"); } if (!bool.TryParse(args[0], out var boolVal)) { if (!int.TryParse(args[0], out var intVal)) { return ConsoleCommandResult.Failed("Expecting 'true' or 'false', '0' or '1'"); } boolVal = intVal != 0; } action(boolVal); return ConsoleCommandResult.Succeeded(); } public static ConsoleCommandResult ExtractInt( Action action, params string[] args) { if (args.Length != 1) { return ConsoleCommandResult.Failed("Requires 1 argument"); } if (!int.TryParse(args[0], out var intVal)) { return ConsoleCommandResult.Failed("Argument (" + args[0] + ") is not a number"); } action(intVal); return ConsoleCommandResult.Succeeded(); } public static ConsoleCommandResult ExtractFloat( Action action, params string[] args) { if (args.Length != 1) { return ConsoleCommandResult.Failed("Requires 1 argument"); } if (!float.TryParse(args[0], out var floatVal)) { return ConsoleCommandResult.Failed("Argument (" + args[0] + ") is not a number"); } action(floatVal); return ConsoleCommandResult.Succeeded(); } } }