WorldTrigger Class
The scope of applications for UnigineScript is limited to implementing materials-related logic (material expressions, scriptable materials, brush materials). Do not use UnigineScript as a language for application logic, please consider C#/C++ instead, as these APIs are the preferred ones. Availability of new Engine features in UnigineScript (beyond its scope of applications) is not guaranteed, as the current level of support assumes only fixing critical issues.
Inherits from: | Node |
See Also#
- A C++ API sample located in the <UnigineSDK>/source/samples/Api/Nodes/WorldTrigger folder
- A C# API sample located in the <UnigineSDK>/source/csharp/samples/Api/Nodes/WorldTrigger folder
- A set of UnigineScript API samples located in the <UnigineSDK>/data/samples/worlds/ folder:
- trigger_00
- trigger_01
- trigger_02
WorldTrigger Class
Members
static 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.
void setEnterCallback ( int func ) #
Sets a callback function to be fired when a node enters the world trigger. The callback function must receive a Node as its first argument. In addition, it can also take 2 arguments of any type.// implement the enter callback
void enter_callback(Node node) {
if(node.getType() == NODE_OBJECT_MESH_STATIC) {
ObjectMeshStatic mesh = node_cast(node);
mesh.setMaterialState("emission",1,0);
}
}
WorldTrigger trigger;
int init() {
// create a world trigger
trigger = new WorldTrigger(vec3(3.0f));
// set the enter callback to be fired when a node enters the world trigger
trigger.setEnterCallback(functionid(enter_callback));
return 1;
}
Arguments
- int func - Callback function identifier.
void setEnterCallbackName ( string name ) #
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 name - Name of the callback function.
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 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.
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 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.
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.
void setLeaveCallback ( int func ) #
Sets a callback function to be fired when a node leaves the world trigger. The callback function must receive a Node as its first argument. In addition, it can also take 2 arguments of any type.// implement the leave callback
void leave_callback(Node node) {
if(node.getType() == NODE_OBJECT_MESH_STATIC) {
ObjectMeshStatic mesh = node_cast(node);
mesh.setMaterialState("emission",0,0);
}
}
WorldTrigger trigger;
int init() {
// create a world trigger
trigger = new WorldTrigger(vec3(3.0f));
// set the callback to be fired when a node leaves the world trigger
trigger.setLeaveCallback(functionid(leave_callback));
return 1;
}
Arguments
- int func - Callback function identifier.
void setLeaveCallbackName ( string name ) #
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 name - Name of the callback function.
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 num ) #
Returns a specified node contained in the world trigger.using Unigine;
namespace UnigineApp
{
class AppWorldLogic : WorldLogic
{
WorldTrigger trigger;
public override bool Init()
{
// create a world trigger
trigger = new WorldTrigger(new vec3(3.0f));
return true;
}
public override bool Update()
{
// press the i key to get the info about nodes inside the trigger
if (trigger != null && Input.IsKeyDown(Input.KEY.I))
{
//get the number of nodes inside the trigger
int numNodes = trigger.NumNodes;
Unigine.Log.Message("The number of nodes inside the trigger is " + numNodes + "\n");
//loop through all nodes to print their names and types
for (int i = 0; i < numNodes; i++)
{
Node node = trigger.GetNode(i);
Unigine.Log.Message("The type of the " + node.Name + " node is " + node.Type + "\n");
}
}
return true;
}
}
}
Arguments
- int num - Node number in range from 0 to the total number of nodes.
Return value
Specified node.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.void setSize ( vec3 size ) #
Updates the current dimensions of the world trigger. The minimum size is vec3(0,0,0).Arguments
- vec3 size - Dimensions of the world trigger. If negative values are provided, 0 will be used instead of them.
vec3 getSize ( ) #
Returns the current dimensions of the world trigger.Return value
Current dimensions of the world trigger.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.
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 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.
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.
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. The default is 0.Arguments
- int touch - Touch mode flag: 1 to enable the touch mode, 0 to disable it.
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.static int type ( ) #
Returns the type of the node.Return value
World type identifier.Last update:
2022-03-10
Help improve this article
Was this article helpful?
(or select a word/phrase and press Ctrl+Enter)