P
P
Pavel2018-09-14 15:52:08
Unity
Pavel, 2018-09-14 15:52:08

How to make GraphicsRaycaster return all UI elements that are raycasted?

Bottom line: I have a scrollrect that can be scrolled vertically. Inside (in its content) there is a scrollrect that can be scrolled horizontally (there may be several of them).
EventSystem events do not work for nested scrollRect, so I decided to do it as follows:
1) All events are caught only by the parent ScrollRect;
2) When the parent ScrollRect fires the OnPointerDown event, I want to do a Raycast, which will return all UI objects that fell under the Raycast. (I do Raycast through GraphicRaycaster)
3) Define the direction vector through OnBeginDrag and, depending on it, move either the parent ScrollRect vertically, or one of the children (which fell under the raycast) horizontally.
The problem is that Raycast returns only one element, and not all that fall under it. In my case it is again the parent ScrollRect.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Gaydak, 2018-09-14
@youkerni

so you give an example of your code, with which you have already received the same "one, not all"
probably you have FindFirstRaycast there
but in general, in the general case you need

EventSystem eventSystem = FindObjectOfType<EventSystem>();
PointerEventData eventData = new PointerEventData(EventSystem.current);
List<RaycastResult> m_RaycastResultCache = new List<RaycastResult>();
 eventSystem.RaycastAll(eventData, m_RaycastResultCache);

for (var i = 0; i < m_RaycastResultCache.Count; ++i)
.....

but this is a general principle of how to get a list List
is all that was touched by the current pointer, and there already among all this ... picking)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question