COMMAND CALLBACKS

You can define callback listeners if you need them in the CommandConsoleManager inspector.

Command Callbacks

There are two callbacks you can use:

  • OnCommandStart: called when command execution starts.
  • OnCommandComplete: called when command execution ends (with or without error).

1. Add these methods in the script where you need the callbacks:


public void OnCommandStart(CommandStartEventArgs args)

{

  

}



public void OnCommandComplete(CommandCompleteEventArgs args)

{



}


2. In the CommandConsoleManager inspector, click the + button to add the listener that you need.

Command Callbacks


3. Drag the object with the script containing the two listeners you defined in step 1.

Command Callbacks


4. Select the corresponding listener method from the dropdown menu.

Command Callbacks


Details about the command starting/completed can be found in the "args" argument of the listener function:


  public void OnCommandStart(CommandStartEventArgs args)

  {

    Type commandClassType = args.commandClassType;      // Type of the command class.

    uint commandId = args.commandId;                    // Unique id of the command.

    string commandString = args.commandString;          // The string used to call the command from the prompt.

    var parameters = args.parameters;                   // Dictionary containing the parameters key/value pairs passed to the command.

  }



  public void OnCommandComplete(CommandCompleteEventArgs args)

  {

    Type commandClassType = args.commandClassType;      // Type of the command class.

    uint commandId = args.commandId;                    // Unique id of the command.

    string commandString = args.commandString;          // The string used to call the command from the prompt.

    var parameters = args.parameters;                   // Dictionary containing the parameters key/value pairs passed to the command.

    string errorMsg = args.errorMessage;                // Error message, empty if suceeded.

    bool succeeded = args.succeeded;                    // If the command ended without errors.

  }