This page has been translated automatically.
Video Tutorials
Interface
Essentials
Advanced
How To
Professional (SIM)
UnigineEditor
Interface Overview
Assets Workflow
Settings and Preferences
Working With Projects
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Lighting
Sandworm
Using Editor Tools for Specific Tasks
Extending Editor Functionality
Built-in Node Types
Nodes
Objects
Effects
Decals
Light Sources
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
Programming
Fundamentals
Setting Up Development Environment
Usage Examples
C++
C#
UnigineScript
UUSL (Unified UNIGINE Shader Language)
Plugins
File Formats
Materials and Shaders
Rebuilding the Engine Tools
GUI
Double Precision Coordinates
API
Containers
Common Functionality
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Objects-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
IG Plugin
CIGIConnector Plugin
Rendering-Related Classes
Content Creation
Content Optimization
Materials
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Tutorials
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.

Unigine.Controls Class

Handles input from the user (keyboard, mouse, joystick or gamepad). It can be used instead of the default engine.controls in one of the two possible ways:

  1. In case you need custom input handling (by AI, for example), you can implement your own controls via ControlsDummy.
  2. You can get the current application controls (i.e. the instance of the default engine controls) via engine.getControls(). After that, you control user input using methods of Controls class exactly the same way as via engine.controls functions.

    Such approach, for example, allows switching between user-controlled input (Controls) and AI-controlled input (ControlsDummy) without having to change the game logic.

    Source code (C#)
    // Get the instance of default engine controls
    Controls controls = engine.getControls();
    controls.setMouseDX(5);

    Here, the function Controls::setMouseDX() does the same as engine.controls.setMouseDX().

The following set of functions is used to register actions (i.e. controls states) that will be executed on the provided input and bind them to specified input events. The actual meaning of all controls registered with STATE_* variables (for example, STATE_JUMP or STATE_FIRE) is defined manually in script by the programmer who uses them. (See how to map controls states and keys).

See Also#

Controls Class

Enums

TYPE#

NameDescription
CONTROLS_APP = 0ControlsApp instance.
CONTROLS_DUMMY = 1ControlsDummy instance.
CONTROLS_GAMEPAD = 2Gamepad controller (e.g., XBox 360, Sixaxis, etc.) as the input device.
CONTROLS_JOYSTICK = 3Joystick as the input device.

Properties

float MouseDY#

The screen position change of the mouse pointer along the y axis during the previous frame.

float MouseDX#

The screen position change of the mouse pointer along the x axis during the previous frame.

string TypeName#

The type name of input controls.

Controls.TYPE Type#

The type of input controls.

Members


Controls ( int type ) #

Creates a smart pointer to Controls.

Arguments

  • int type - Type of the controls to be created.

void SetState ( int state, int value ) #

Toggles the state of the given control on or off.

Arguments

  • int state - State (one of CONTROLS_STATE_* variables).
  • int value - Positive value to "press" the corresponding control; 0 to release it.

int GetState ( int state ) #

Returns the state of a given control (pressed or unpressed).

Arguments

  • int state - Control state number. Possible values are in range [STATE_FORWARD;NUM_STATES]. For full list of available controls see Unigine::Controls:: Enumeration at the end of the article.

Return value

1 if the control is pressed; otherwise, 0.

int GetStateByName ( string name ) #

Returns the state of a given control (pressed or unpressed) by the control state name.

Arguments

  • string name - Name of the control state. For full list of available controls see Unigine::Controls:: Enumeration at the end of the article.

Return value

1 if the control is pressed; otherwise, 0.

string GetStateName ( int state ) #

Returns the name of a given control state as a string.

Arguments

  • int state - Control state number. Possible values are in range [STATE_FORWARD;NUM_STATES]. For full list of available controls see Unigine::Controls:: Enumeration at the end of the article.

Return value

Name of the control state.

int ClearState ( int state ) #

Returns a control state and clears it to 0 (not pressed). This function allows to handle control only once even if it is kept pressed over several frames.

Arguments

Return value

Returns the state of the given control: 1 if the control is pressed; otherwise,0.

bool SaveState ( Stream stream ) #

Saves controls settings into the stream.

Example using saveState() and restoreState() methods:

Source code (C#)
// Get the instance of default engine controls and set its state
Controls controls = new engine.Controls();
controls.MouseDX = 5.0f;

// save state
Blob blob_state = new Blob();
controls.SaveState(blob_state);

// change the node state
controls.MouseDX = 1.0f;

// restore state
blob_state.SeekSet(0);	// returning the carriage to the start of the blob
controls.RestoreState(blob_state);

Arguments

  • Stream stream - The stream to save controls data.

Return value

true if the controls settings are saved successfully; otherwise, false.

bool RestoreState ( Stream stream ) #

Restores controls settings from the stream.

Example using saveState() and restoreState() methods:

Source code (C#)
// Get the instance of default engine controls and set its state
Controls controls = new engine.Controls();
controls.MouseDX = 5.0f;

// save state
Blob blob_state = new Blob();
controls.SaveState(blob_state);

// change the node state
controls.MouseDX = 1.0f;

// restore state
blob_state.SeekSet(0);	// returning the carriage to the start of the blob
controls.RestoreState(blob_state);

Arguments

  • Stream stream - The stream to save controls data.

Return value

true if the controls settings are restored successfully; otherwise, false.
Last update: 2022-12-14
Build: ()