Closed nantianliao closed 5 years ago
You can try adding a "drag event blocker" to the button object.
using UnityEngine;
using UnityEngine.EventSystems;
public class DragEventBlocker : MonoBehaviour
, IDragHandler
{
public void OnDrag(PointerEventData eventData)
{
Debug.Log("Drag event blocked");
}
}
This blocker will block the drag event so it can't be sent to their parent (ScrollRect).
Thank you. The button has responded. In the same way, ScrollRect will not respond. Is there a better way to solve the conflict between them?
You mean you can't drag ScrollRect now? I suggest add a background image to the buttons as a draggable zone.
If you have to drag & click at the same time (which I don't recommend, it's kind of an odd behavior). Try this
using HTC.UnityPlugin.Pointer3D;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class MyButton : Button
, IPointer3DPressEnterHandler
, IPointer3DPressExitHandler
{
public override void OnPointerDown(PointerEventData eventData) { }
public override void OnPointerUp(PointerEventData eventData) { }
public override void OnPointerClick(PointerEventData eventData) { }
public virtual void OnPointer3DPressEnter(Pointer3DEventData eventData)
{
// Perform OnPointerDown transition
base.OnPointerDown(eventData);
}
public virtual void OnPointer3DPressExit(Pointer3DEventData eventData)
{
// Perform OnPointerUp transition
base.OnPointerUp(eventData);
// Click only if button is released
if (!eventData.GetPress())
{
// Perform OnClick event
base.OnPointerClick(eventData);
}
}
}
UnityEngine.UI.Button only response to IPointerClickHandler, which will be canceled if it's parent received Drag event. So here override OnPointerClick with OnPointer3DPressExit event. Notice that IPointer3DPressEnterHandler and IPointer3DPressExitHandler only defined in VIU, built-in handler doesn't include them.
For example, a button under ScrollRect, although it responds to clicking animation, can't trigger anything other than that. My device is Vive Focus.