I’m using the Touchscript plugin and I want to subscribe to its TapGesture class Tapped Event. How do I do that? Or How do I subscribe to Events in general and just listen to them through my custom event node. Also, is it easier to do this in NodeCanvas? If so, How?
The included “Code Event” node is only able to subscribe to events of type System.Action or System.Action(T). this is the case in NodeCanvas as well.
If you have created a custom event node though, here is an example of how:
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
usingUnityEngine;
usingSystem.Collections;
namespaceFlowCanvas.Nodes{
publicclassCustomEventNodeExample:EventNode{
privateFlowOutput raised;
protectedoverridevoidRegisterPorts(){
raised=AddFlowOutput("Out");
}
publicoverridevoidOnGraphStarted(){
TapGesture.Tapped+=EventRaised;
}
publicoverridevoidOnGraphStoped(){
TapGesture.Tapped-=EventRaised;
}
voidEventRaised(){
raised.Call(newFlow());
}
}
}
Is this what you mean or something different?
Thanks
protectedoverridestring[]GetTargetEvents(){returnnull;}//you don't need this in this case.
protectedoverridevoidRegisterPorts(){
raised=AddFlowOutput("Out");
}
publicoverridevoidOnGraphStarted(){
base.OnGraphStarted();//make sure to call base
target.value.Tapped+=EventRaised;
}
publicoverridevoidOnGraphStoped(){
base.OnGraphStoped();//make sure to call base
target.value.Tapped-=EventRaised;
}
voidEventRaised(){
raised.Call(newFlow());
}
}
}
Notice that here, we instead derive from the generic class of EventNode, with an type argument of the type we need.
‘target.value’ gives you the actual component which is always the same type as the generic argument.
As with all the other event nodes, you can either leave the field in the node inspector empty to get the component automaticaly from the FlowScriptController gameobject, or you can assign a reference manualy.