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
Программирование
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
Engine-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
Внимание! Эта версия документация УСТАРЕЛА, поскольку относится к более ранней версии SDK! Пожалуйста, переключитесь на самую актуальную документацию для последней версии SDK.
Внимание! Эта версия документации описывает устаревшую версию SDK, которая больше не поддерживается! Пожалуйста, обновитесь до последней версии SDK.

Unigine::NodeTrigger Class

Header:#include <UnigineNodes.h>
Inherits:Node

A trigger node is a zero-sized node that has no visual representation and fires callbacks when:

  • It is enabled/disabled (the enabled callback function is called).
  • Its transformation is changed (the position callback function is called).
The trigger node is usually added as a child node to another node, so that the callbacks will be fired on the parent node enabling/disabling or transforming.

For example, to detect if some node has been enabled (for example, a world clutter node that renders nodes only around the camera has enabled it), the trigger node is added as a child to this node and fires the corresponding callback.

Creating a Trigger Node

To create a trigger node, simply call the NodeTrigger constructor and then add the node as a child to another node, for which callbacks should be fired.

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

#include <UnigineLogic.h>
#include <UnigineStreams.h>
#include <UnigineObjects.h>
#include <UnigineNodes.h>
#include <UnigineCallback.h>
#include <UnigineLog.h>

using namespace Unigine;

class AppWorldLogic : public Unigine::WorldLogic {

public:
	AppWorldLogic();
	virtual ~AppWorldLogic();

	virtual int init();
	
	virtual int update();
	virtual int render();
	virtual int flush();
	
	virtual int shutdown();
	virtual int destroy();
	
	virtual int save(const Unigine::StreamPtr &stream);
	virtual int restore(const Unigine::StreamPtr &stream);

private:

	ObjectMeshStaticPtr object;
	NodeTriggerPtr trigger;
};
Source code (C++)
// AppWorldLogic.cpp

#include "AppWorldLogic.h"

#include <UnigineEditor.h>

using namespace Math;

int AppWorldLogic::init() {
	
	// create a mesh
	MeshPtr mesh = Mesh::create();
	mesh->addBoxSurface("box_0", vec3(1.0f));
	// create a node (e.g. an instance of the ObjectMeshStatic class)
	object = ObjectMeshStatic::create(mesh);
	object->release();
	object->setMaterial("mesh_base", "*");
	object->setMaterialParameter("albedo_color", vec4(1.0f, 0.0f, 0.0f, 1.0f), 0);

	// create a trigger node
	trigger = NodeTrigger::create();
	trigger->release();
	// add it as a child to the static mesh
	object->addWorldChild(trigger->getNode());
	// add nodes to UnigineEditor
	Editor::get()->addNode(object->getNode());

	return 1;
}

int AppWorldLogic::shutdown() {
	
	// clear pointers
	trigger.clear();
	object.clear();

	return 1;
}

Editing a Trigger Node

Editing a trigger node includes implementing and specifying the enabled and postion callbacks that are fired on enabling or positioning the trigger node correspondingly.

The callback function must receive at least 1 argument of the NodeTrigger type. In addition, it can also take another 2 arguments of any type.

The callback functions can be set by callback pointers or names:

  1. setEnabledCallback() and setPositionCallback() receive pointers to the callback functions.
  2. setEnabledCallbackName() and setPositionCallbackName() receive names of the callback functions implemented in the world script (on the UnigineScript side). In this case, the callback functions can receive no arguments or 1 argument of the Node or NodeTrigger type.
    Notice
    These methods allow for setting callbacks with 0 or 1 argument only. To set callbacks with additional arguments, use setEnabledCallback()/setPositionCallback().

Setting the callback functions by pointers:

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

#include <UnigineLogic.h>
#include <UnigineStreams.h>
#include <UnigineObjects.h>
#include <UnigineNodes.h>
#include <UnigineCallback.h>
#include <UnigineLog.h>

using namespace Unigine;

class AppWorldLogic : public Unigine::WorldLogic {
	
public:
	AppWorldLogic();
	virtual ~AppWorldLogic();
	
	virtual int init();
	
	virtual int update();
	virtual int render();
	virtual int flush();
	
	virtual int shutdown();
	virtual int destroy();
	
	virtual int save(const Unigine::StreamPtr &stream);
	virtual int restore(const Unigine::StreamPtr &stream);

private:

	ObjectMeshStaticPtr object;
	NodeTriggerPtr trigger;

	void position_callback(NodeTriggerPtr trigger)
	{
		Log::message("Object position has been changed. New position is: (%f %f %f)\n", trigger->getWorldPosition().x, trigger->getWorldPosition().y, trigger->getWorldPosition().z);
	}

	void enabled_callback(NodeTriggerPtr trigger)
	{
		Log::message("The enabled flag is %d\n", trigger->isEnabled());
	}
};
Source code (C++)
// AppWorldLogic.cpp

#include "AppWorldLogic.h"

#include <UnigineEditor.h>

using namespace Math;

int AppWorldLogic::init() {
	
	// create a mesh
	MeshPtr mesh = Mesh::create();
	mesh->addBoxSurface("box_0", vec3(1.0f));
	// create a node (e.g. an instance of the ObjectMeshStatic class)
	object = ObjectMeshStatic::create(mesh);
	object->release();
	object->setMaterial("mesh_base", "*");
	object->setMaterialParameter("albedo_color", vec4(1.0f, 0.0f, 0.0f, 1.0f), 0);

	// create node trigger
	trigger = NodeTrigger::create();
	trigger->release();
	// add the trigger node to the static mesh as a child node
	object->addWorldChild(trigger->getNode());
	// add nodes to UnigineEditor
	Editor::get()->addNode(object->getNode());
	
	// set the enabled and position callbacks
	trigger->setEnabledCallback(MakeCallback(this, &AppWorldLogic::enabled_callback));
	trigger->setPositionCallback(MakeCallback(this, &AppWorldLogic::position_callback));

	return 1;
}

int AppWorldLogic::shutdown() {
	
	// clear pointers
	trigger.clear();
	object.clear();

	return 1;
}

Setting the callback functions by their names:

  1. Implement the callback functions in the world script (on the UnigineScript side).
  2. Set the callback functions for the trigger node by using their names on the C++ side (AppWorldLogic.cpp).
Source code (UnigineScript)
// unigine_project.cpp

#include <core/unigine.h>

// the enabled callback
void enabled_callback(NodeTrigger trigger) {
	
	log.message("Enabled flag is %d\n", trigger.isEnabled());
}
// the position callback
void position_callback(NodeTrigger trigger) {
	
	log.message("The node position is %s\n", typeinfo(trigger.getWorldPosition()));
}

int init() {

	// some logic if required
	return 1;
}
Source code (C++)
// AppWorldLogic.cpp

#include "AppWorldLogic.h"

#include <UnigineCallback.h>
#include <UnigineEditor.h>
#include <UnigineNodes.h>

using namespace Unigine;

int AppWorldLogic::init() {
	
	// create a trigger node 
	NodeTriggerPtr trigger = NodeTrigger::create();
	// release script ownership
	trigger->release();
	// add the node to UnigineEditor
	Editor::get()->addNode(trigger->getNode());
	
	// set the enabled and position callbacks
	trigger->setEnabledCallbackName("enabled_callback");
	trigger->setPositionCallbackName("position_callback");

	return 1;
}

NodeTrigger Class

Members


static NodeTriggerPtr create()

Constructor. Creates a new trigger node.

Ptr<NodeTrigger> cast(const Ptr<Node> & node)

Casts a NodeTrigger out of the Node instance.

Arguments

  • const Ptr<Node> & node - Pointer to Node.

Return value

Pointer to NodeTrigger.

void setEnabledCallback(const Ptr<EnabledCallback> & func)

Sets a pointer to a callback to be fired when the trigger node is enabled. The callback function must receive a NodeTrigger as its first argument. In addition, it can also take 2 arguments of any type.
Source code (C++)
// implement the enabled callback
void AppWorldLogic::enabled_callback(NodeTriggerPtr trigger){
	Log::message("The enabled flag is %d\n", trigger->isEnabled());
}

int AppWorldLogic::init() {

	// create a trigger node
	NodeTriggerPtr trigger = NodeTrigger::create();
	
	// set the enabled callback to be fired when the node is enabled/disabled
	trigger->setEnabledCallback(MakeCallback(this, &AppWorldLogic::enabled_callback));
	
	return 1;
}

Arguments

  • const Ptr<EnabledCallback> & func - Pointer to the callback function.

void setEnabledCallbackName(const char * name)

Sets a callback function to be fired when the trigger node is enabled. The callback function must be implemented in the world script (on the UnigineScript side). The callback function can take no arguments, a Node or a NodeTrigger.
Notice
The method allows for setting a callback with 0 or 1 argument only. To set the callback with additional arguments, use setEnabledCallback().
On UnigineScript side:
Source code (UnigineScript)
// implement the enabled callback
void enabled_callback(Node node) {
	log.message("The enabled flag is %d\n", node.isEnabled());
}
On C++ side:
Source code (C++)
int AppWorldLogic::init() {

	// create a trigger node
	NodeTriggerPtr trigger = NodeTrigger::create();
	
	// set the enabled callback to be fired when the node is enabled/disabled
	trigger->setEnabledCallbackName("enabled_callback");
	
	return 1;
}

Arguments

  • const char * name - Name of the callback function implemented in the world script (UnigineScript side).

const char * getEnabledCallbackName()

Returns the name of callback function to be fired on enabling the trigger node. This callback function is set via setEnabledCallbackName().

Return value

Name of the callback function implemented in the world script (UnigineScript side).

void setPositionCallback(const Ptr<PositionCallback> & func)

Sets a pointer to a callback to be fired when the trigger node position has changed. The callback function must receive a NodeTrigger as its first argument. In addition, it can also take 2 arguments of any type.
Source code (C++)
// implement the position callback
void AppWorldLogic::position_callback(NodeTriggerPtr trigger){
	Log::message("A new position of the node is (%f %f %f)\n", trigger->getWorldPosition().x, trigger->getWorldPosition().y, trigger->getWorldPosition().z);
}

int AppWorldLogic::init() {

	// create a trigger node
	NodeTriggerPtr trigger = NodeTrigger::create();
	
	// set the position callback to be fired when the node position is changed
	trigger->setPositionCallback(MakeCallback(this, &AppWorldLogic::position_callback));
	
	return 1;
}

Arguments

  • const Ptr<PositionCallback> & func - Pointer to the callback function.

void setPositionCallbackName(const char * name)

Sets a callback function to be fired when the trigger node position has changed. The callback function must be implemented in the world script (on the UnigineScript side). The callback function can take no arguments, a Node or a NodeTrigger.
Notice
The method allows for setting a callback with 0 or 1 argument only. To set the callback with additional arguments, use setPositionCallback().
On UnigineScript side:
Source code (UnigineScript)
// implement the position callback
void position_callback(Node node) {
	log.message("A new position of the node is %s\n", typeinfo(node.getWorldPosition()));
}
On C++ side:
Source code (C++)
int AppWorldLogic::init() {

	// create a trigger node
	NodeTriggerPtr trigger = NodeTrigger::create();
	
	// set the position callback to be fired when the node position is changed
	trigger->setPositionCallbackName("position_callback");
	
	return 1;
}

Arguments

  • const char * name - Name of the callback function implemented in the world script (UnigineScript side).

const char * getPositionCallbackName()

Returns the name of callback function to be fired on changing the trigger node position. This function is set by using the setPositionCallbackName() function.

Return value

Name of the callback function implemented in the world script (UnigineScript side).

int type()

Returns the type of the node.

Return value

NodeTrigger type identifier.
Last update: 04.06.2018
Build: ()