First off, let me say I’m really impressed with the quality and polish of both FlowCanvas and NodeCanvas. It’s saving me and my team a lot of headaches in the design tool useability department.
Now onto business. I’m trying to code a custom event node for some puzzle trigger behaviors I’ve written in C#, meant to behave similarly to the TriggerEnter or CollisionEnter nodes. The code for the node itself thus far is pretty straightforward:
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
[Name("Puzzle Trigger")]
[Category("Events/Puzzle")]
[Description("Called when Puzzle Trigger is activated")]
However, the node is non-functional. I’ve created several events in the base puzzle trigger script that should be viable for registration, but I’m not sure what step I’m meant to take to insure that it registers to the message router. I notice that it has a lot of the base Unity events hard-coded into it like so:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
voidOnMouseDown(){
Dispatch("OnMouseDown",null);
}
voidOnMouseDrag(){
Dispatch("OnMouseDrag",null);
}
voidOnMouseEnter(){
Dispatch("OnMouseEnter",null);
}
voidOnMouseExit(){
Dispatch("OnMouseExit",null);
}
//etc...
— but I’m unsure at what point these get added to the dictionary or how it knows to register the event provided through the PuzzleTrigger. Can you offer any insight into how to approach this?
Since you you have c# events that you want to use, indeed the way you did it was the one to go. Alternatively you could also use the “Code Event” node which subscribes to a c# event through reflection, but of course having all 3 of those events together in one node like you did is a bit more nice.
Just to clarify, regarding the MessageRouter and the way the included nodes work through the use of GetTargetEvents(), it is usefull when not working with c# events, but rather with messages send to the target gameobject instead. In this case, a method with the same name as the event name needs to be implemented in MessageRouter.cs, which is a partial class, thus no source code changes needed.
But, in your case, what you did was the best approach anyway 🙂
Cheers!
Join us on Discord: https://discord.gg/97q2Rjh
Author
Posts
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic.
Login
Register
By registering on this website you agree to our Privacy Policy.