/// <summary> /// Find current target. /// </summary> /// <param name="eventData">Event data.</param> protected virtual void FindCurrentTarget(PointerEventData eventData) { var new_target = FindTarget(eventData); if (new_target != CurrentTarget) { if (CurrentTarget != null) { CurrentTarget.DropCanceled(Data, eventData); } OnTargetChanged(CurrentTarget, new_target); } if (new_target != null) { // set cursor can drop Cursor.SetCursor(AllowDropCursor, AllowDropCursorHotSpot, Compatibility.GetCursorMode()); } else { // set cursor fail drop Cursor.SetCursor(DeniedDropCursor, DeniedDropCursorHotSpot, Compatibility.GetCursorMode()); } CurrentTarget = new_target; }
/// <summary> /// When dragging is occurring this will be called every time the cursor is moved. /// </summary> /// <param name="eventData">Current event data.</param> public virtual void OnDrag(PointerEventData eventData) { if (!IsDragged) { return; } oldTarget = currentTarget; currentTarget = FindTarget(eventData); if ((oldTarget != null) && (currentTarget != oldTarget)) { oldTarget.DropCanceled(Data, eventData); } if (currentTarget != null) { // set cursor can drop Cursor.SetCursor(AllowDropCursor, AllowDropCursorHotSpot, Compatibility.GetCursorMode()); } else { // set cursor fail drop Cursor.SetCursor(DeniedDropCursor, DeniedDropCursorHotSpot, Compatibility.GetCursorMode()); } Vector2 point; if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(CanvasTransform as RectTransform, Input.mousePosition, eventData.pressEventCamera, out point)) { return; } DragPoint.localPosition = point; }