Beispiel #1
0
    private bool TryEndDragOrDetectClickOrTap()
    {
        if (CanEndDrag())
        {
            if (IsDragging)
            {
                IsDragging = false;

                OnEndDrag.Dispatch(LastDragPosition);

                DebugLog(type + "End drag");

                return(true);
            }
            else if (IsAttemptingDrag)
            {
                IsAttemptingDrag = false;

                if (CanTriggerPrimaryAction())
                {
                    OnPrimaryAction.Dispatch(LastDragPosition);
                }

                DebugLog(type + "End drag with click or tap");

                return(true);
            }
        }

        return(false);
    }
Beispiel #2
0
    private bool TryDrag()
    {
        if (IsDragging)
        {
            Vector2 currentPosition = GetScreenPosition();

            // Check if mouse or touch has moved since last frame
            if (currentPosition != LastDragPosition)
            {
                OnDrag.Dispatch(GetScreenPosition());
                LastDragPosition = currentPosition;

                DebugLog(type + "Dragging");
            }

            // Want to block if dragging, whether a displacement was made or not
            return(true);
        }

        return(false);
    }
Beispiel #3
0
    private bool TryStartClickTapOrDrag()
    {
        Assert.IsFalse(IsDragging); // IsDragging here is irrelevant based on Update ordering

        if (IsAttemptingDrag)
        {
            LastDragPosition = GetScreenPosition();
            float distanceFromStart = (LastDragPosition - DragStartPosition).magnitude;

            if (distanceFromStart >= DragThresholdInPixels)
            {
                IsDragging       = true;
                IsAttemptingDrag = false;

                OnStartDrag.Dispatch(LastDragPosition);

                DebugLog(type + "Started drag");

                return(true);
            }
        }
        else if (CanStartDrag())
        {
            Vector2 screenPosition = GetScreenPosition();

            if (DisableOverUI && IsPositionOverUI(screenPosition))
            {
                return(true);
            }

            IsAttemptingDrag  = true;
            DragStartPosition = screenPosition;

            DebugLog(type + "Attempting to start drag");

            return(true);
        }

        return(false);
    }