HandDrag.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using UnityEngine;
  2. using UnityEngine.EventSystems;
  3. namespace HexaCrazy
  4. {
  5. public sealed class HandDrag : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler, IPointerClickHandler
  6. {
  7. public HexGameApp app;
  8. public int slot;
  9. int? dragPointerId;
  10. public void OnBeginDrag(PointerEventData e)
  11. {
  12. // Releasing over this slot would otherwise dispatch a click before endDrag.
  13. e.eligibleForClick = false;
  14. if (app.BeginHandDrag(slot, e.position))
  15. dragPointerId = e.pointerId;
  16. }
  17. public void OnDrag(PointerEventData e)
  18. {
  19. if (dragPointerId == e.pointerId)
  20. app.MoveHandDrag(e.position);
  21. }
  22. public void OnEndDrag(PointerEventData e)
  23. {
  24. if (dragPointerId != e.pointerId) return;
  25. dragPointerId = null;
  26. app.EndHandDrag(e.position);
  27. }
  28. public void OnPointerClick(PointerEventData e)
  29. {
  30. app.SelectHand(slot);
  31. }
  32. }
  33. }