Exemplo n.º 1
0
 public void OnPointerUp(PointerEventData eventData)
 {
     if (eventData.button == PointerEventData.InputButton.Left)
     {
         dragging = false;
         OnEndDragging?.Invoke(this);
     }
 }
Exemplo n.º 2
0
    private void OnMouseUp()
    {
        AdjustPointerID();
        if (opStatus == "down")
        {
            OnClicked.SC(dragFrom.x, dragFrom.y);
        }
        else if (opStatus == "dragging")
        {
            OnEndDragging.SC(dragFrom.x, dragFrom.y, lastDraggingPos.x, lastDraggingPos.y);
        }

        opStatus = "default";
    }
Exemplo n.º 3
0
 public void OnEndDrag(PointerEventData eventData)
 {
     _currentDragPoint = eventData.position;
     UpdateDragDto();
     OnEndDragging?.Invoke(_dragDto);
 }
Exemplo n.º 4
0
    private void Update()
    {
        AdjustPointerID();
        if (!CheckPointerRelativePosition(out Vector2 pt))
        {
            return;
        }

        if (opStatus == "scaling")
        {
            if (Input.touchCount == 0)
            {
                OnEndDragging.SC(dragFrom.x, dragFrom.y, lastDraggingPos.x, lastDraggingPos.y);
                opStatus = "default";
            }
            else if (Input.touchCount == 1)
            {
                lastDraggingPos = pt;
                opStatus        = "dragging";
            }
            else
            {
                if (!CheckPointerRelativePosition(out Vector2 pt1, 1))
                {
                    return;
                }

                var centreFrom = (pt0From + pt1From) / 2;
                var centreTo   = (pt1 + pt) / 2;
                var dPos       = centreTo - centreFrom;

                draggingOffset += dPos;
                lastDraggingPos = pt;
                // 暂时屏蔽双指拖动效果,会影响缩放手势的位置计算
                // OnDragging.SC(dragFrom.x, dragFrom.y, dragFrom.x + draggingOffset.x, dragFrom.y + draggingOffset.y);

                var s = (pt1 - pt).magnitude / (pt1From - pt0From).magnitude;
                totalScale *= s;
                OnScaling.SC(totalScale, centreTo.x, centreTo.y);

                pt0From = pt;
                pt1From = pt1;
            }
        }
        else if (Input.touchCount == 2)
        {
            if (!CheckPointerRelativePosition(out Vector2 pt1, 1))
            {
                return;
            }
            if (opStatus != "dragging")
            {
                lastDraggingPos = dragFrom = pt;
                draggingOffset  = Vector2.zero;
                OnStartDragging.SC(dragFrom.x, dragFrom.y);
            }

            pt0From    = pt;
            pt1From    = pt1;
            totalScale = 1;
            opStatus   = "scaling";

            var centreFrom = (pt0From + pt1From) / 2;
            OnStartScaling.SC();
        }
    }
Exemplo n.º 5
0
 /// <summary>
 /// Invokes the <see cref="OnEndDrag"/> event
 /// </summary>
 public void OnEndDrag(PointerEventData eventData)
 {
     OnEndDragging?.Invoke(eventData);
     IsBeingMoved   = false;
     Cursor.visible = true;
 }