做项目遇到一个需求,点击按下触发事件的同时 ,如果不松手直接移动 ,需要能拖拽scrollview
点击进入我用的是eventTrigger组件
同时触发scrollview移动 在按钮上挂载下面的脚本
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class SCCtrl : MonoBehaviour,IBeginDragHandler,IEndDragHandler,IDragHandler
{
public void OnBeginDrag(PointerEventData data)
{
GameObject.Find("Scroll View").GetComponent<ScrollRect>().OnBeginDrag(data);
}
public void OnDrag(PointerEventData data)
{
GameObject.Find("Scroll View").GetComponent<ScrollRect>().OnDrag(data);
}
public void OnEndDrag(PointerEventData data)
{
GameObject.Find("Scroll View").GetComponent<ScrollRect>().OnEndDrag(data);
}
}
测试 按下鼠标拖动的同时触发点击事件和拖拽事件 需求通过