I’m a bit new to Unity and I’m still exploring NC and it’s really cool so far! I’m still learning how to effectively use it though. However, I’m not new to coding or game development, so it’s ok to use big words 😉
I recently came across a problem where I need to handle input from the player in the game world, but that input should be blocked if they were just clicking on a GUI element. I had if (Input.GetButtonDown("Fire1")) { } in an Action, so it still runs even though the GUI element should have blocked it, but at least I got the event easily.
I’m currently using Unity’s Event System (with Graphic/Physics Raycasters) so the GUI blocks input on GOs in the world. The problem is adding pointer events to Actions after they’ve been filtered by the casters. So I just want a “filtered” pointer up/down handler in an Action (not an NC Condition since that got messy _really_ fast). What’s the best way to handle this situation?
Hello and sorry for the late reply due to summer vacation.
Thank you! I am glad you like NodeCanvas thus far 🙂
Please excuse me in advance if I misunderstood the question, but you can if required get a callback for the pointer-based unity events in actions. One way to do that, is by using the [EventReceiver] attribute, which accepts a params array of messages/events (in string names) to subscribe the action to, where the gameobject that would be used for those callbacks, will be the “agent”. Here is an example of how this can be done:
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
using UnityEngine;
using UnityEngine.EventSystems;
using NodeCanvas.Framework;
using ParadoxNotion.Design;
namespaceNodeCanvas.Tasks.Actions{
[EventReceiver("OnPointerDown","OnPointerUp")]
publicclassExample:ActionTask<Transform>{
privateboolpointerState;
protectedoverride voidOnUpdate(){
if(pointerState){
EndAction();
}
}
voidOnPointerDown(PointerEventData eventData){
Debug.Log("Down");
pointerState=true;
}
voidOnPointerUp(PointerEventData eventData){
Debug.Log("Up");
pointerState=false;
}
}
}
Is this indeed what you’ve asked, or did I misunderstood the question.
Please let me know.