using UnityEngine; using UnityEngine.EventSystems; namespace HexaCrazy { public sealed class HandDrag : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler, IPointerClickHandler { public HexGameApp app; public int slot; int? dragPointerId; public void OnBeginDrag(PointerEventData e) { // Releasing over this slot would otherwise dispatch a click before endDrag. e.eligibleForClick = false; if (app.BeginHandDrag(slot, e.position)) dragPointerId = e.pointerId; } public void OnDrag(PointerEventData e) { if (dragPointerId == e.pointerId) app.MoveHandDrag(e.position); } public void OnEndDrag(PointerEventData e) { if (dragPointerId != e.pointerId) return; dragPointerId = null; app.EndHandDrag(e.position); } public void OnPointerClick(PointerEventData e) { app.SelectHand(slot); } } }