This page has been translated automatically.
UnigineEditor
Interface Overview
Assets Workflow
Settings and Preferences
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Landscape Tool
Using Editor Tools for Specific Tasks
FAQ
Programming
Fundamentals
Setting Up Development Environment
Usage Examples
UnigineScript
C++
C#
UUSL (Unified UNIGINE Shader Language)
File Formats
Rebuilding the Engine and Tools
GUI
Double Precision Coordinates
API
Containers
Common Functionality
Controls-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
CIGI Client Plugin
Rendering-Related Classes
Warning! This version of documentation is OUTDATED, as it describes an older SDK version! Please switch to the documentation for the latest SDK version.
Warning! This version of documentation describes an old SDK version which is no longer supported! Please upgrade to the latest SDK version.

Controls console-related parameters.

Adding Console Command with Several Arguments

The Console class can be used to create custom user console commands with a different number of arguments. This section provides an example of how to create a custom console command with several arguments.

Prior Knowledge
It is supposed that you have already created an empty C# project by using UNIGINE SDK Browser.

In the example below, we perform the following actions:

  • Define and implement AppWorldLogic instance methods for console commands.
  • Get the console instance (which has a singleton implementation) and add a new command.
1. Adding Instance Methods

In this example, we define three methods in the AppWorldLogic.cs file: one as a callback for a console command and another two methods for actions depending on the number of arguments:

  • choose_command() selects the appropriate method.
  • action_no_args() is called if there are no console arguments.
  • action_one_arg() is called if an argument was passed.
Source code (C#)
// AppWorldLogic.cs

public static void choose_command(int argc, string[] argv)
{
	for (int i = 0; i < argc; i++) {
		Log.message("arg[{0}]: {1}\n", i, argv[i]);
	}
	// note: the first element of argv is the name of console command
	if (argc == 1) {
		action_no_args();
	}
	else if (argc == 2) {
		 action_one_arg(argv[1]);
	}
	// for more arguments:
	//else if (...) {
	    //	// etc
	//}
}

// write the message into console, if there are no arguments
public static void action_no_args()
{
    Log.message("first action! no arguments!\n");
}
// write the message into console, if an argument was passed
public static void action_one_arg(string s)
{
    Log.message("second action! the argument is:{0} \n", s);
}

Arguments argc and argv are used to get the arguments count and arguments vector.

Notice
The first element of argv always keeps the name of a console command. Thus, argc is always >= 1. To get the first passed argument, you should use argv[1].
2. Adding Custom Console Command

Add a custom command to the AppWorldLogic.cs file by using addCommand() function. By adding this code into init() function of the AppWorldLogic class, the engine adds a new console command on AppWorldLogic class instance initialization.

Source code (C++)
// AppWorldLogic.cs

using Unigine;

/* ... */

public override int init()
{
	// get the existing singleton Console instance and add a command
    Unigine.Console console = Unigine.Console.get();
    console.addCommand("console_action","Performs custom console action",choose_command);

	return 1;
}

/* ... */
3. Running Sample

After building the project, run it and open the console. Write recently created command to check the result:

Output
#if you write "console_action"
arg[0]: console_action
first action! no arguments!

#if you write "console_action arg"
arg[0]: console action
arg[1]: arg
second action! the argument is:arg

To remove the added console command, use removeCommand() method.

Console Class

Members


void setActivity(int activity)

Opens or closes the console. By default the console is closed.

Arguments

  • int activity - Positive integer to make the console active (opened); otherwise, 0.

int getActivity()

Returns a value indicating if the console is opened or closed.

Return value

Returns 1 if the console is active (opened); otherwise, 0.

void setBackgroundColor(vec4 color)

Sets a background color for the console.

Arguments

  • vec4 color - Four-component vector specifying the color in the RGBA format.

int isCommand(string name)

Returns a value indicating if a command with a given name exists.

Arguments

  • string name - The command name.

Return value

Returns 1 if the command with a given name exists; otherwise, 0.

string getCommandDescription(string name)

Returns the description of the console command by its name. If the name isn't specified, an empty string will be returned.

Arguments

  • string name - The command name.

Return value

The command description if it exists; otherwise, an empty string.

string getCommandName(int num)

Returns the name of the console command by its number in the array of the existing commands.

Arguments

  • int num - The command number.

Return value

The command name if it is found in the array of the existing commands; otherwise, an empty string.

void setErrorColor(vec4 color)

Sets a color for error messages in the console.

Arguments

  • vec4 color - Four-component vector specifying the color in the RGBA format.

void setFloat(string name, float value)

Sets a float value for a given variable.

Arguments

  • string name - The variable name.
  • float value - Float value of the variable.

float getFloat(string name)

Returns a float value of a given variable.

Arguments

  • string name - The variable name.

Return value

Float value of the variable.

float getFloatMax(string name)

Returns a maximum float value for a given variable.

Arguments

  • string name - Variable name.

Return value

Maximum float value of the variable.

float getFloatMin(string name)

Returns a minimum float value for a given variable.

Arguments

  • string name - Variable name.

Return value

Minimum float value of the variable.

int isFloat(string name)

Checks if the value set for the given console variable is of the float type.

Arguments

  • string name - The variable name.

Return value

1 if the variable value is float; otherwise, 0.

void setInt(string name, int value)

Sets an integer value for a given variable.

Arguments

  • string name - Variable name.
  • int value - Value of the variable.

int getInt(string name)

Returns an integer value of a given variable.

Arguments

  • string name - Variable name.

Return value

Integer value of the variable.

int getIntMax(string name)

Returns a maximum integer value for a given variable.

Arguments

  • string name - Variable name.

Return value

Maximum integer value of the variable.

int getIntMin(string name)

Returns a minimum integer value for a given variable.

Arguments

  • string name - Variable name.

Return value

Minimum integer value of the variable.

int isInt(string name)

Checks if the value of the given console variable is of the integer type.

Arguments

  • string name - The variable name.

Return value

1 if the variable value is int; otherwise, 0.

void setLock(int lock)

Disables or enables the console. By default the console is enabled.

Arguments

  • int lock - Positive integer to disable the console; otherwise, 0.

int getLock()

Checks if the console is disabled.

Return value

1 if the console is disabled; otherwise, 0.

void setMessageColor(vec4 color)

Sets a color for ordinary messages in the console.

Arguments

  • vec4 color - Four-component vector specifying the color in the RGBA format.

int getNumCommands()

Returns the number of all available console commands, including the custom ones.

Return value

The number of available console commands.

int getNumVariables()

Returns the number of all available console variables.

Return value

The number of available console variables.

void setOutputCallback(OutputCallback func)

Sets a callback function that will be executed when a text is output to the console.The function is useful when you implement a custom console, for example. The callback function must receive 2 arguments:
  • string text - a text that is output to the console,
  • int level - one of the LEVEL_* variables that indicate the type of the output text. The value can be important for setting a color for console messages, for example.
Source code (C#)
// the callback function
private static void output_callback(string text, int level)
{
	switch (level):
		case Unigine.Console.LEVEL_NORMAL:
			// logic for ordinary messages
		case Unigine.Console.LEVEL_WARNING:
			// logic for warnings
		case Unigine.Console.LEVEL_ERROR:
			// logic for error messages
}

public override int init()
{
	// set the callback
	Unigine.Console console = Unigine.Console.get();
	console.setOutputCallback(output_callback);
	
	return 1;
}

Arguments

  • OutputCallback func - Name of the callback function. The callback arguments must be (string text,int level).

void setPrompt(string str)

Updates the console prompt. The default prompt is Unigine~#.

Arguments

  • string str - New console prompt.

void setString(string name, string value)

Sets a string value for a given variable.

Arguments

  • string name - The variable name.
  • string value - String value of the variable.

string getString(string name)

Returns the string value of a given variable.

Arguments

  • string name - The variable name.

Return value

String value of the variable.

int isString(string name)

Checks if the value of the given console variable is of the string type.

Arguments

  • string name - The variable name.

Return value

1 if the variable value is string; otherwise, 0.

void setTextColor(vec4 color)

Sets a common font color for the console.

Arguments

  • vec4 color - Four-component vector specifying the color in the RGBA format.

int isVariable(string name)

Returns a value indicating if a variable with a given name exists.

Arguments

  • string name - The variable name.

Return value

1 if the variable exists; otherwise, 0.

string getVariableDescription(string name)

Returns the description of the console variable by its name. If the name isn't specified, an empty string will be returned.

Arguments

  • string name - The variable name.

Return value

The variable description if it exists; otherwise, an empty string.

string getVariableName(int num)

Returns the name of the console variable by its number in the array of the existing variables.

Arguments

  • int num - The variable number.

Return value

The variable name if it is found in the array of the existing variables; otherwise, an empty string.

void setVec2(string name, vec2 value)

Sets a two component vector for the console variable.

Arguments

  • string name - Name of the variable.
  • vec2 value - Value of the variable.

vec2 getVec2(string name)

Returns the two component vector console variable.

Arguments

  • string name - Name of the variable.

Return value

Value of the variable.

int isVec2(string name)

Returns a value indicating if the console variable is a two component vector.

Arguments

  • string name - Name of the variable.

Return value

1 if the variable is a two component vector; otherwise, 0.

void setVec3(string name, vec3 value)

Sets a three component vector for the console variable.

Arguments

  • string name - Name of the variable.
  • vec3 value - Value of the variable.

vec3 getVec3(string name)

Returns the three component vector console variable.

Arguments

  • string name - Name of the variable.

Return value

Value of the variable.

int isVec3(string name)

Returns a value indicating if the console variable is a three component vector.

Arguments

  • string name - Name of the variable.

Return value

1 if the variable is a three component vector; otherwise, 0.

void setVec4(string name, vec4 value)

Sets a four component vector for the console variable.

Arguments

  • string name - Name of the variable.
  • vec4 value - Value of the variable.

vec4 getVec4(string name)

Returns the four component vector console variable.

Arguments

  • string name - Name of the variable.

Return value

Value of the variable.

int isVec4(string name)

Returns a value indicating if the console variable is a four component vector.

Arguments

  • string name

Return value

1 if the variable is a three component vector; otherwise, 0.

void setWarningColor(vec4 color)

Sets a color for warning messages in the console.

Arguments

  • vec4 color - Four-component vector specifying the color in the RGBA format.

int addCommand(string name, string desc, CommandCallback callback)

Adds a custom console command bound to a given callback function.

Arguments

  • string name - Name of the new console command.
  • string desc - Short description to be displayed in the console.
  • CommandCallback callback - The callback function that is run on command execution. The callback arguments must be (int argc,string[] argv,...).

Return value

1 if the custom command is added successfully; otherwise, 0.

void flush()

Forces to execute all queued console commands.

int removeCommand(string name)

Removes a custom console command.

Arguments

  • string name - Name of the custom console command.

Return value

1 if the custom command has been removed successfully; otherwise, 0.

void run(string command)

Runs the specified console command.

Arguments

  • string command - A console command with arguments.

int LEVEL_ERROR

Description

An error message.

int LEVEL_NORMAL

Description

An ordinary message.

int

Description

A warning.
Last update: 2018-08-10
Build: ()