您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
66 行
1.9 KiB
66 行
1.9 KiB
using System;
|
|
|
|
namespace UnityConsole
|
|
{
|
|
public static class ConsoleCommandHelpers
|
|
{
|
|
public static ConsoleCommandResult ExtractBool(
|
|
Action<bool> 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<int> 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<float> 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();
|
|
}
|
|
}
|
|
}
|