#nullable enable using System; using TMPro; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; namespace ReplacedPerson.Runtime { [RequireComponent(typeof(RectTransform), typeof(Button))] public sealed class ReplacedCardDragHandler : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler { private Canvas? _canvas; private RectTransform? _ghost; private ReplacedCardMotion? _motion; private Action? _dropAction; private Vector2 _dragStart; private bool _hasDragStart; public void Configure(Action dropAction) { _dropAction = dropAction; } public void OnBeginDrag(PointerEventData eventData) { CleanupGhost(); _dragStart = eventData.position; _hasDragStart = true; _canvas = GetComponentInParent()?.rootCanvas; if (_canvas == null) return; _motion = GetComponent(); _motion?.SetDragging(true); _ghost = CreateGhost(_canvas.transform); UpdateGhostPosition(eventData); } public void OnDrag(PointerEventData eventData) { UpdateGhostPosition(eventData); } public void OnEndDrag(PointerEventData eventData) { var moved = _hasDragStart && (eventData.position - _dragStart).sqrMagnitude >= 100f; _motion?.SetDragging(false); _motion = null; CleanupGhost(); _hasDragStart = false; if (moved && _dropAction != null) _dropAction(eventData.position); else GetComponent