CreatesEvent
Introduction
Variables in entities and screens can have events which are raised whenever the variable is changed. These events can be used to broadcast changes (such as in the case of INotifyPropertyChanged) or to perform other custom logic such as updating a health bar when health changes.
Example : Adding an Event to a Variable by Drag+Dropping
To add an event to a variable:
Expand your Screen or Entity's Objects folder
Drag+drop the variable onto the Events folder
Open your project in Visual Studio
Look for the Events file for your Screen or Entity, which will be named ScreenOrEntityName.Events.cs. In this example, the file is named FanRight.Events.cs.
Add code to the event to respond to the variable change.
Example : Assigning Additional Event Handlers
When a variable event is created, an event handler is automatically added. In the example above, the handler is named OnAfterForceVelocityXSet. You can also manually create event handlers purely in custom code. By drag+dropping the variable onto the Events folder, the Variable's CreatesEvent property is set to true.
This results in two events being created:
Before<VariableName>Set - for example BeforeForceVelocityXSet
After<VariableName>Set - for example AfterForceVelocityXSet
These can be seen in generated code:
Notice that the Before event is an Action which takes a float. This argument contains the new value, enabling the handler to decide how to respond to the new value before it has been assigned. These can be handled in custom code. For example, the following code could be used to print out that the variable is being assigned:
Last updated