Class EventBus
A global container that maps Event names and Component references to actions for registered listeners.
Assembly: Unity.VisualScripting.Core.dll
Syntax
public static class EventBus
Examples
The following example shows how to use the EventBus to send a custom event from a script to a node in
a graph. It also shows how to use the EventBus as a global event manager by executing a callback in a
script, not just a node.
For more information on how to create custom event nodes refer to the
User Manual.
In this example we've added some code to a GameObject. This code checks for when the user presses a sequence of
keys to enable a cheat code, then triggers the CheatCodeActivated
event. We register the
CheatCodeActivated
event in the Start
method. The Update
method triggers the event twice
with 2 different targets: one for the CheatCodeActivated
callback and the other to trigger the
CheatCodeEnabled Node.
The CheatCodeEnabled Node:
Methods
Register<TArgs>(EventHook, Action<TArgs>)
Declaration
public static void Register<TArgs>(EventHook hook, Action<TArgs> handler)
Parameters
Type Parameters
Trigger(string, GameObject)
Declaration
public static void Trigger(string name, GameObject target)
Parameters
Trigger(EventHook)
Declaration
public static void Trigger(EventHook hook)
Parameters
Trigger<TArgs>(string, GameObject, TArgs)
Declaration
public static void Trigger<TArgs>(string name, GameObject target, TArgs args)
Parameters
Type Parameters
Trigger<TArgs>(EventHook, TArgs)
Declaration
public static void Trigger<TArgs>(EventHook hook, TArgs args)
Parameters
Type |
Name |
Description |
EventHook |
hook |
|
TArgs |
args |
|
Type Parameters
Unregister(EventHook, Delegate)
Declaration
public static void Unregister(EventHook hook, Delegate handler)
Parameters