关于ScrollView拖拽事件和Button点击事件冲突解决方法

来源:互联网 发布:网络电视apk软件下载 编辑:程序博客网 时间:2024/05/29 10:46

将脚本挂载在ScrollView结构下需要响应时间的对象上

using UnityEngine.UI;using UnityEngine.EventSystems;using UnityEngine;public class GDragEventDispatcher : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler{    ScrollRect anotherScrollRect;    private Image thisRaycast;    void Awake()    {        //FindScrollRect(gameObject);        //if (anotherScrollRect)        //{        //    thisRaycast = gameObject.GetComponent<Image>();        //}    }    void Start()    {        FindScrollRect(gameObject);        if (anotherScrollRect)        {            thisRaycast = gameObject.GetComponent<Image>();        }    }    private void FindScrollRect(GameObject obj)    {        GameObject tempObj = obj.transform.parent.gameObject;        //Debug.Log("测试"+tempObj.gameObject.name);        anotherScrollRect = tempObj.GetComponent<ScrollRect>();        if (anotherScrollRect)        {            //Debug.Log(anotherScrollRect.gameObject.name);            return;        }        else        {            FindScrollRect(tempObj);        }    }    public void OnBeginDrag(PointerEventData eventData)    {        if (anotherScrollRect)        {            anotherScrollRect.OnBeginDrag(eventData);        }        if (thisRaycast)        {            thisRaycast.raycastTarget = false;        }    }    public void OnDrag(PointerEventData eventData)    {        if (anotherScrollRect)        {            anotherScrollRect.OnDrag(eventData);        }    }    public void OnEndDrag(PointerEventData eventData)    {        if (anotherScrollRect)        {            anotherScrollRect.OnEndDrag(eventData);        }        if (thisRaycast)        {            thisRaycast.raycastTarget = true;        }    }}


阅读全文
0 0
原创粉丝点击