I implemented mobile rotation control with IPointerDownHandler and IDragHandler. It seems fine if the movement is fast enough, but there's a serious flaw that the OnDrag event never invoked if the dragging amount is very tiny.
Here's the code.
using UnityEngine;
using UnityEngine.EventSystems;
[RequireComponent(typeof(CanvasGroup))]
public class MobileFPSRotationPanel : MonoBehaviour, MobileFPSUIElement, IPointerDownHandler, IDragHandler, IEndDragHandler {
...
public void OnDrag(PointerEventData eventData) {
Debug.Log("Drag"); <- It's not invoked if the dragging is too small.
eventData.Use();
Vector2 currentTouchPosition = eventData.position;
m_Movement = currentTouchPosition - m_PreviousTouchPosition;
m_PreviousTouchPosition = currentTouchPosition;
}
public void OnEndDrag(PointerEventData eventData) {
Debug.Log("EndDrag");
m_Pressing = false;
m_Movement = Vector2.zero;
}
public void OnPointerDown(PointerEventData eventData) {
Debug.Log("PointerDown");
if (Interactable == false) {
return;
}
eventData.Use();
m_Pressing = true;
m_Movement = Vector2.zero;
m_PreviousTouchPosition = eventData.position;
}
...
}
I reported a lot of people have been annoyed by this glitch, which makes it hard to precise aiming. Is this a glitch or an intended feature of Unity? If it's intended, then how should I detect every drag movement even if it's super tiny?
Using Unity 2019.4.3f1.