Hi. I would like to cancel all of the UI events like click,etc when I drag my finger to left/right side and drop it like when I scroll using scroll rect UI, it cancels all button clicks.
Because I have a problem when I drag and drop my finger using my custom script(GetTouch and use touchPhase so I can recognize drag and drop happens or not) in my scene, it can fire a button click as well but I do not want.
Thanks
I did something similar a while back - I found this article helpful: https://coeurdecode.com/game%20development/2015/10/20/bubbling-events-in-unity/
Basically you need to add your own handlers for OnBeginDrag/OnPointerDown etc… After you’ve handled that in your code you can decide whether to propogate the event to all the remaining UI elements in the scene by using ‘ExecuteHierarchy’ (or you can decide not to do that if you don’t want to).
Thank you I read it but it did not solve my problem.
First I drag and drop my finger using Input.GetTouch and detect it as a drag/drop event by comparison of the distance between first finger and the position of the dropped/released finger but it can click big UI buttons as well. If the distance is greater than a threshold I want to detect it as drag and drop event that I have already done but it can fire ui events as well. If the distance is lower than the threshold I want to handle UI events and throw away my drag/drop mechanism
This is the problem. I do not want to propagate my event but in contrast I want to cancel it(button click)
Thank you I almost solved it but not completely!
I can use Event system handlers such as begin and end drag and drop for special objects like plane or screen sprite and compare the drag/drop distance to a threshold. The problem was that I had wanted to use global Input.GetTouch instead of using event system handlers for the special object.
Please see the image below. If I would like to detect a drag and drop only in the green rectangle, it is ok and can write a script with drag and drop Handler and assign it to the green plane or sprite. but If I want to detect a drag and drop in other elements like red rectangle button, I want to cancel button click event and instead fire drag and drop event if the distance is greater than a threshold.
Other problem is that I should use GetTouch to recognize drag and drop because my scene is not 2D and can change.
I’m not sure how you would do that with Input.GetTouch. I suppose you could just disable the EventSystem completely and use Input.GetTouch. If you then wanted to activate a normal UI button you could activate the EventSystem and call ExecuteEvent at the mouse position to touch any buttons beneath it.
yes I have used EventSystem.current.enabled=false or true and it does work but it is not appropriate.
Suppose I want to implement ui scrolling like unity. When you scroll using ScrollRect and Mask components, it does not deactivate EventSystem. Can anyone know another way to cancel the click for the current button when we scroll?