This page has been translated automatically.
Getting Started
Migrating to UNIGINE 2.0
C++ API Migration
UnigineScript
The Language
Core Library
Engine Library
Node-Related Classes
GUI-Related Classes
Plugins Library
High-Level Systems
Samples
Usage Examples
C++ API
API Reference
Integration Samples
Usage Examples
C++ Plugins
注意! 这个版本的文档是过时的,因为它描述了一个较老的SDK版本!请切换到最新SDK版本的文档。
注意! 这个版本的文档描述了一个不再受支持的旧SDK版本!请升级到最新的SDK版本。

WorldTrigger Class

World triggers fire callbacks when any nodes (colliders or not) get inside or outside of them. The trigger can detect the node of all the types by its bounding box.

You can either specify a list of nodes, for which the callbacks will be fired, or let the trigger react on all nodes (default behavior). In the latter case the list of target nodes should be empty. There can be also specified a list of nodes, which are skipped by the trigger and are free to pass unnoticed.

The callback function of World trigger will be actually executed only when the next engine function is called: that is, before flush() (in the current frame), or before the update() (in the next frame) — whatever comes first.

Notice
If you have moved some nodes and want to get callbacks based on changed positions in the same frame, you need to call engine.world.updateSpatial() first.

WorldTrigger Class

This class inherits from Node

Members


WorldTrigger (vec3 size)

Constructor. Creates a new world trigger with given dimensions.

Arguments

  • vec3 size - Dimensions of the new world trigger. If negative values are provided, 0 will be used instead of them.

string getEnterCallbackName ()

Returns the name of callback function to be fired on entering the world trigger. This callback function is set via setEnterCallbackName().

Return value

Name of the callback function.

void getExcludeNodes (int nodes[] = [])

Returns the current list of excluded nodes, on which the world trigger does not react.

Arguments

  • int nodes[] - ID of the array with excluded nodes.

void getExcludeTypes (int nodes[] = [])

Returns the current list of excluded node types, on which the world trigger does not react.

Arguments

  • int nodes[] - ID of the array with excluded node types.

string getLeaveCallbackName ()

Returns the name of the callback function name to be fired on leaving the world trigger. This callback function is set via setLeaveCallbackName().

Return value

Name of the callback function.

Node getNode (int id)

Returns a specified node contained in the world trigger.

Arguments

  • int id - Number of the node.

Return value

Specified node.

void getNodes (int id)

Gets nodes contained in the trigger and appends them to the vector with a given ID.

Arguments

  • int id - ID of the vector with nodes.

int getNumNodes ()

Returns the number of nodes contained in the world trigger.

Return value

Number of nodes.

vec3 getSize ()

Returns the current dimensions of the world trigger.

Return value

Current dimensions.

void getTargetNodes (int nodes[] = [])

Returns the current list of target nodes, which fire callbacks. If this list is empty, all nodes fire callbacks.

Arguments

  • int nodes[] - ID of the array with target nodes.

void getTargetTypes (int nodes[] = [])

Returns the current list of target node types, which fire callbacks. If this list is empty, all nodes fire callbacks.

Arguments

  • int nodes[] - ID of the array with target node types.

int isTouch ()

Returns a value indicating if a touch mode is enabled for the trigger. With this mode on, the trigger will react to the node by partial contact. When set to off, the trigger reacts only if the whole bounding sphere/box gets inside or outside of it.

Return value

1 if the touch mode is enabled; otherwise, 0.

void setEnterCallbackName (string function)

Sets a callback function to be fired when nodes are entering the world trigger. Unlike setEnterCallback(), this callback function accepts a node that entered the world trigger and world trigger itself as arguments.

Arguments

  • string function - Name of the callback function.

Examples

Source code (UnigineScript)
WorldTrigger trigger;

// Implement a two-argument callback function that takes Node
// and WorldTrigger as arguments.
int on_enter_callback_func(Node node, WorldTrigger trigger) {
	// Your callback code
	return 1;
}

// Set the callback fired when nodes enter the world trigger.
trigger.setEnterCallbackName("on_enter_callback_func");

void setEnterCallback (variable function, variable arg0 = 0, variable arg1 = 0)

Sets a callback function to be fired when nodes are entering the world trigger. Unlike setEnterCallbackName(), this callback function accepts a node that entered the world trigger as the first argument. In addition, it can also take any other two arguments. However, it can also receive no arguments.

Arguments

  • variable function - Name of the callback function.
  • variable arg0 - Argument to the function. This is an optional parameter.
  • variable arg1 - Argument to the function. This is an optional parameter.

Examples

Source code (UnigineScript)
WorldTrigger trigger;
MyClass arg0; // it can be an argument of any type

// Implement a callback function that takes Node as the 1-st argument
// It can also take any other 2 arguments, if necessary
int on_enter_callback_func(Node node, MyClass arg0) {
	// Your callback code
	return 1;
}

// Set the callback fired when nodes enter the world trigger
trigger.setEnterCallback("on_enter_callback_func", arg0);

void setExcludeNodes (int nodes[] = [])

Sets a list of excluded nodes, on which the world trigger will not react.

Arguments

  • int nodes[] - ID of the array with excluded nodes.

void setExcludeTypes (int nodes[] = [])

Sets a list of excluded node types, on which the world trigger will not react.

Arguments

  • int nodes[] - ID of the array with excluded node types.

void setLeaveCallbackName (string function)

Sets a callback function to be fired when nodes are leaving the world trigger. Unlike setLeaveCallback(), this callback function accepts a node that left the world trigger and world trigger itself as arguments. However, it can also receive no arguments.

Arguments

  • string function - Name of the callback function.

Examples

Source code (UnigineScript)
WorldTrigger trigger;

// Implement a two-argument callback function that takes Node
// and WorldTrigger as arguments.
int on_leave_callback_func(Node node, WorldTrigger trigger) {
	// Your callback code
	return 1;
}

// Set the callback fired when nodes leave the world trigger
trigger.setLeaveCallbackName("on_leave_callback_func");

void setLeaveCallback (variable function, variable arg0 = 0, variable arg1 = 0)

Sets a callback function to be fired when nodes are leaving the world trigger. Unlike setLeaveCallbackName(), this callback function accepts a node that left the world trigger as the first argument. In addition, it can also take any other two arguments. However, it can also receive no arguments.

Arguments

  • variable function - Name of the callback function.
  • variable arg0 - Argument to the function. This is an optional parameter.
  • variable arg1 - Argument to the function. This is an optional parameter.

Examples

Source code (UnigineScript)
WorldTrigger trigger;
MyClass arg0; // it can be an argument of any type

// Implement a callback function that takes Node as the 1-st argument
// It can also take any other 2 arguments, if necessary
int on_leave_callback_func(Node node, MyClass arg0) {
	// Your callback code
	return 1;
}

// Set the callback fired when nodes leave the world trigger
trigger.setLeaveCallback("on_leave_callback_func", arg0);

void setSize (vec3 size)

Updates the current dimensions of the world trigger.

Arguments

  • vec3 size - Dimensions of the world trigger. If negative values are provided, 0 will be used instead of them.

void setTargetNodes (int nodes[] = [])

Sets a list of target nodes, which will fire callbacks. If this list is empty, all nodes fire callbacks.

Arguments

  • int nodes[] - ID of the array with target nodes.

void setTargetTypes (int nodes[] = [])

Sets a list of target node types, which will fire callbacks. If this list is empty, all nodes fire callbacks..

Arguments

  • int nodes[] - ID of the array with target node types.

void setTouch (int touch)

Sets a touch mode for the trigger. With this mode on, the trigger will react to the node by partial contact. When set to off, the trigger reacts only if the whole bounding sphere/box gets inside or outside of it.

Arguments

  • int touch - Touch mode flag: positive number to enable mode, 0 to disable.
Last update: 2017-07-03
Build: ()