- Home /
4.6 UI EventSystem Handler Redirection?
So here's the situation:
I have a UI Panel with a bunch of UI Images as children. I would like those images to respond to dragging, clicking, double-clicking, etc, so adding a script to them that implements IBeginDragHandler, IPointerClickHandler, etc. would make for a beautiful solution.
BUT here's the catch: The UI "colliders" for these images are rectangular (and match the bounds of the sprite if I'm not mistaken), which means that if you have 2 images stacked on top of each other, the mouse interactions are intercepted by the top one even in the transparent areas of that image. First off, I believe I have a solution to determine which image the mouse should actually interact with: By using EventSystem.current.RaycastAll and then iterating through the results and comparing the intercept locations for each image with the corresponding pixel value at that location to determine if it is an opaque pixel or not, I can locate the top-most image where the mouse cursor is actually over the opaque part of the image...
What I'm having trouble with is this: How can I control the flow of a given drag/click event to apply to the correct IBeginDragHandler, IPointerClickHandler etc based on the above pixel-perfect approach to finding the true image under the cursor? It seems to me that the functions implemented by the IBeginDragHandler/IPointerClickHandler are always called on the first encountered object and I'm having a difficult time figuring out if / how it's possible to somehow re-route those events such that they pass through to the correct image per my above pixel-perfect "mouse over" detection. I hope it is possible to still rely on those interfaces somehow rather than implementing my own drag/click functionality in this situation (it seems so much more elegant)!
Thanks for any assistance or direction you can provide!
Your answer
Follow this Question
Related Questions
How to use the deselect Event Trigger? 1 Answer
4.6 UI OnBeginDrag event handler doesn't seem to work. 1 Answer
4.6 UI "image" is capturing clicks - how to prevent? 3 Answers
[4.6 - UI] How to call an event with button when the pointer is up the button image. 1 Answer
4.6 UI Dynamic button event system PointerEnter, PointerExit, PointerUp etc. 1 Answer