Created this utility script that can raise graph events in response to Unity Events.
I’m using it in UI’s dynamically created by behaviors from data-bound templates.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingNodeCanvas.Framework;
usingParadoxNotion;
usingUnityEngine;
namespaceNodeCanvas.Tasks.Actions
{
/// <summary>
/// Sends a graph event. The primary intended usage of this is to attach the SendEvent method to some Unity event (e.g. a button click)
/// and have that raise the graph event. The argument was previously set by a graph action, e.g. when instancing UI controls from a
/// behavior tree for each item in a list, set the argument field to the currently iterated value. Clicking the button will then raise
/// the graph event with that argument - each instanced button using the proper value.
/// </summary>
publicclassSendEventScript:MonoBehaviour
{
/// <summary>
/// The event argument. This will not serialize (or show in the inspector), but using the basic object type is what allows sending
/// any argument value, including types that Unity cannot serialize.
/// This should not be a big issue, as this should be runtime data anyway.
/// </summary>
publicSystem.Objectargument;
/// <summary>
/// The name of the event.
/// </summary>
publicstringeventName;
/// <summary>
/// The recipient of the event. Null for a global event.