列表叠层 判断方向非子列表方向就透传给父列表
using RK_Runtime.RK_Space_UI;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class VC_SubScrollViewCheck : RK_UIMonoViewComponent, IBeginDragHandler, IDragHandler, IEndDragHandler, IScrollHandler, IInitializePotentialDragHandler, ICanvasElement, ILayoutGroup
{
    public ScrollRect ParentScrollRect;
    private bool m_IsDrag = false;
    private Vector2 m_PrePos;

    public float minWidth;

    public void CalculateLayoutInputHorizontal()
    {
        ParentScrollRect.CalculateLayoutInputHorizontal();
    }

    public void CalculateLayoutInputVertical()
    {
        ParentScrollRect.CalculateLayoutInputVertical();
    }

    public void GraphicUpdateComplete()
    {
        ParentScrollRect.GraphicUpdateComplete();
    }

    public bool IsDestroyed()
    {
        return ParentScrollRect.IsDestroyed();
    }

    public void LayoutComplete()
    {
        ParentScrollRect.LayoutComplete();
    }

    public void OnBeginDrag(PointerEventData eventData)
    {
        m_IsDrag = true;
        m_PrePos = eventData.position;
        PassEvent(eventData, ExecuteEvents.beginDragHandler);
    }

    public void OnDrag(PointerEventData eventData)
    {
        bool parDir = ParentScrollRect.vertical;
        var offset = eventData.position - m_PrePos;
        var x = Mathf.Abs(offset.x);
        var y = Mathf.Abs(offset.y);

        if (parDir)
        {
            if (y > x)
            {
                PassEvent(eventData, ExecuteEvents.dragHandler);
            }
        }
        else
        {
            if (y < x)
            {
                PassEvent(eventData, ExecuteEvents.dragHandler);
            }
        }

        m_PrePos = eventData.position;
    }

    public void OnEndDrag(PointerEventData eventData)
    {
        m_IsDrag = false;
        PassEvent(eventData, ExecuteEvents.endDragHandler);
    }

    public void OnInitializePotentialDrag(PointerEventData eventData)
    {
        PassEvent(eventData, ExecuteEvents.initializePotentialDrag);
    }

    public void OnScroll(PointerEventData eventData)
    {
        PassEvent(eventData, ExecuteEvents.scrollHandler);
    }

    //把事件透下去
    public void PassEvent<T>(PointerEventData data, ExecuteEvents.EventFunction<T> function)
        where T : IEventSystemHandler
    {
        //List<RaycastResult> results = new List<RaycastResult>();
        //EventSystem.current.RaycastAll(data, results);
        //GameObject current = data.pointerCurrentRaycast.gameObject;
        //for (int i = 0; i < results.Count; i++)
        //{
        //    if (current != results[i].gameObject && GetComponent<VC_SubScrollViewCheck>() == null)
        //    {
        //        ExecuteEvents.Execute(ParentScrollRect.gameObject, data, function);
        //        //RaycastAll后ugui会自己排序,如果你只想响应透下去的最近的一个响应,这里ExecuteEvents.Execute后直接break就行。
        //        break;
        //    }
        //}
        ExecuteEvents.Execute(ParentScrollRect.gameObject, data, function);
    }

    public void Rebuild(CanvasUpdate executing)
    {
        ParentScrollRect.Rebuild(executing);
    }

    public void SetLayoutHorizontal()
    {
        ParentScrollRect.SetLayoutHorizontal();
    }

    public void SetLayoutVertical()
    {
        ParentScrollRect.SetLayoutVertical();
    }
}



首页 我的博客
粤ICP备17103704号