Event Handlers |
The article describes how to create event handlers.
You can create an event handler via any of the three basic scripting methods: in C# file, using C# script and using Flow Graph.
In the examples below, a code will be created that is called when the scene is initialized. To do this, select the scene object, in Settings Window go to the Events tab. Next, click on the add handler button. In this case, we need an Enabled Event (scene enable event).
For those who are familiar with programming, the easiest way is to use C# scripts.
After clicking on the add button, a context menu will appear with a choice of what type of object to create.
When you select a C# script, a C# Script object is created. It adds the handler code.
To test, you can add the code Log.Warning("Test");
After starting the scene in the Player App (Play button in the Ribbon), a message will be displayed in the player console.
To add handlers in a regular C# file, the resource must have a basic C# class. To create a base class, when creating a resource, you need to enable the 'Create C# class' checkbox.
After creating the resource, two files will appear, one of which will be a regular C# file.
Now you can create a handler.
And add Log.Warning("Test");
After starting the scene in the Player App (Play button in the Ribbon), a message will be displayed in the player console.
This section describes how to create a handler using the Flow Graph visual scripting tools.
First, you need to add a handler in the same way it was added in the previous examples.
The Flow Graph Editor will open. It will have one Event Handler node.
Next, attach another node to it with a call to the Log.Warning method. To do this, in Resources Window, find the Log.Warning method and drop it into the workspace. The method is in All types\NeoAxis\Log.
Now you can adjust the properties of the new node. Enable the Flow Support property in order to be able to connect the node with others. Fill in the Message parameter.
Next, connect the first node's Handler Flow output to the second's node Entry input.
After starting the scene in the Player App (Play button in the Ribbon), a message will be displayed in the player console.
To enable event handler in the editor select your Event Handler component in the Objects window. Add Editor flag to When Enable property.