Adding Commands
A guide to creating console commands and getting them into Aplos Console.
How it works
An overview of the command system and how commands are registered and invoked.
- Authoring — commands live as objects and can be used interchangeably.
- Registration — command objects are registered against the console so that they show up as entries within the console command list.
- Execution — when selected, the underlying configured action is invoked against the selected command.
Developing commands
How to author a command object and attach it in Unity.
- Create the command object.
- Create a new class component inheriting from
AplosConsoleCommandConstructor. - Add the methods that contain the behaviour required for each command, and register them as part of the
RegisterCommandoverride.
- Create a new class component inheriting from
- In Unity, create a new GameObject and attach the recently created component.
Example
public class UnityLogCommand : AplosConsoleCommandConstructor
{
public override void RegisterCommand(IConsoleCommandSystem commandSystem)
{
AplosDebugCommand printLog = new AplosDebugCommand(
"printLog",
"Command for printing some random text to Unity's Console.",
"printLog",
this.LogToUnityConsoleCommand);
commandSystem.RegisterCommand(printLog);
}
private void LogToUnityConsoleCommand()
{
// Arrange
// Act
Debug.Log("Log this to Unity Console.");
}
}
Adding commands during runtime
How to register a command while the console is already running.
- Open the
AplosConsolecomponent from the inspector. - Add a new entry to
AddOnCommandsand pass in a command GameObject. - Press the Refresh Command List button.
- Show all commands from the Console view.
Configuring pre-loaded commands
How to bundle commands into a configuration so they load with the console.
- Create the command GameObject.
- Create a prefab of the command GameObject.
- Locate your instance of the
AplosCommandConfigurationScriptableObject. If one does not exist, create a new command configuration by right-clicking in the Project area and navigating to Create → AplosConsole → Aplos Command Configuration.- If a new command configuration is created, set this ScriptableObject on the
AplosConsolecomponent'sCommandConfigurationfield and theAplosInputManagercomponent'sSettingsfield.
- If a new command configuration is created, set this ScriptableObject on the
- Play the scene.
- Open the console by pressing
`key. - Show all commands (command:
help).