qq_14956487
2018-05-15 10:32
采纳率: 22.7%
浏览 1.5k
已采纳

ScrollView点击按钮不能进行拖动

quick-cocos-lua 中menu嵌套ScrollView点击按钮不能进行拖动

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • qq_41990768 2018-05-15 12:57
    已采纳

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

    [csharp] view plain copy

    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;  
        }  
    }  
    

    }

    点赞 打赏 评论

相关推荐 更多相似问题