Skip to content

Command console

Robin van Ee edited this page Apr 23, 2023 · 2 revisions

Basic usage

The command console can be added to the scene by adding the command console prefab.

The syntax starts with the command name, then arguments separated by comma. Trailing / prefixed spaces are ignored, so commands can be written: command,argument0,argument1 or command, argument0, argument1

The only built-in command is echo, which will repeat text back at you echo, hello world

image

Defining new commands

Commands need to implement the IConsoleCommand interface. A simple example can be found in EchoCommand.cs.

public class EchoCommand: IConsoleCommand
{
    public string Word => "echo";
    public ConsoleArgumentType[] Arguments { get; } = {ConsoleArgumentType.String};
		
    public void Execute(object[] arguments, Action<string> onError)
    {
	// Argument count and type are guaranteed to be correct at this point
	var message = (string)arguments[0];
			
	CommandConsole.LogMessage(message);
    }
}

This command can then be registered by calling CommandConsole.RegisterCommand(new EchoCommand());

Clone this wiki locally