UI Nested Scrollrect, Second ScrollRect Ignores First

This question asked before but no answer, So I Asked Again

I have 3 Panels Nested. 2 have scroll Rect Attached. Lets called “panel1”,“panel2” & “panel2”

  • panel1 has horizontal move Scroll Rect
    Attached and controls panel2

  • panel2 has vertical scroll Rect
    Attached and controls panel3

Picture below Describe the Situation

52011-untitled-1.png

Gray box = panel1 |
Pink box = panel2 |
Blue box = panel2

Problem

Panel2 Scroll Rect only has Vertical move so you can go up and down. when I move horizontally it ignores Panel1 Horizontal movements. So I can ones move Horizontaly and Panel 2 got focus. and I Cant Go back to Panel1.

Also
The Question Asked before Here
I haven’t found anything in this form too

Place this on your child scroll rects. I cannot take credit for this, Googling nested scrollrects helped me find this thread http://forum.unity3d.com/threads/nested-scrollrect.268551/.

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System;
using UnityEngine.EventSystems;
 
public class ScrollRectEx : ScrollRect {
 
    private bool routeToParent = false;
 
 
    /// <summary>
    /// Do action for all parents
    /// </summary>
    private void DoForParents<T>(Action<T> action) where T:IEventSystemHandler
    {
        Transform parent = transform.parent;
        while(parent != null) {
            foreach(var component in parent.GetComponents<Component>()) {
                if(component is T)
                    action((T)(IEventSystemHandler)component);
            }
            parent = parent.parent;
        }
    }
 
    /// <summary>
    /// Always route initialize potential drag event to parents
    /// </summary>
    public override void OnInitializePotentialDrag (PointerEventData eventData)
    {
        DoForParents<IInitializePotentialDragHandler>((parent) => { parent.OnInitializePotentialDrag(eventData); });
        base.OnInitializePotentialDrag (eventData);
    }
 
    /// <summary>
    /// Drag event
    /// </summary>
    public override void OnDrag (UnityEngine.EventSystems.PointerEventData eventData)
    {
        if(routeToParent)
            DoForParents<IDragHandler>((parent) => { parent.OnDrag(eventData); });
        else
            base.OnDrag (eventData);
    }
 
    /// <summary>
    /// Begin drag event
    /// </summary>
    public override void OnBeginDrag (UnityEngine.EventSystems.PointerEventData eventData)
    {
        if(!horizontal && Math.Abs (eventData.delta.x) > Math.Abs (eventData.delta.y))
            routeToParent = true;
        else if(!vertical && Math.Abs (eventData.delta.x) < Math.Abs (eventData.delta.y))
            routeToParent = true;
        else
            routeToParent = false;
 
        if(routeToParent)
            DoForParents<IBeginDragHandler>((parent) => { parent.OnBeginDrag(eventData); });
        else
            base.OnBeginDrag (eventData);
    }
 
    /// <summary>
    /// End drag event
    /// </summary>
    public override void OnEndDrag (UnityEngine.EventSystems.PointerEventData eventData)
    {
        if(routeToParent)
            DoForParents<IEndDragHandler>((parent) => { parent.OnEndDrag(eventData); });
        else
            base.OnEndDrag (eventData);
        routeToParent = false;
    }
}

Here’s my take on the solution by @CaptainSchnittchen. I wanted to get rid of the upwards traversal of the hierarchy, as our project will run on mobile devices with limited processing power. So i got rid of that by letting the developer assign up to 1 ScrollRect as parent, and delegate the event as the original solution, but without using the System.Action delegate pattern (in order to avoid garbage generation). My solution consists of 2 files, the ScrollRectNested component and the ScrollRectNestedEditor editor class. The editor is needed as I’m adding a new property and the standard ScrollRectEditor wont draw it by default.

https://forum.unity3d.com/threads/nested-scrollrect.268551/#post-2950475

Can anyone tell me how to use scrollrect.OnScroll(PointerEventData data)