/// <summary>
        /// Determines whether all the condinitions, needed to process a gesture, are met.
        /// </summary>
        /// <param name="gesture">The gesture to examine.</param>
        /// <returns></returns>
        protected virtual bool CanHandleGesture(Gesture gesture)
        {
            if (!this.IsEnabled)
            {
                return(false);
            }

            if (this.Panel.WaitingForLayout)
            {
                return(false);
            }

            if (gesture.GestureType == KnownGesture.Flick)
            {
                DragDirection flickDirection = GestureBehavior.GetDragDirection((gesture as FlickGesture).Velocity);
                if (this.View.Orientation == Orientation.Horizontal)
                {
                    return(flickDirection == DragDirection.Horizontal);
                }

                return(flickDirection == DragDirection.Vertical);
            }

            return(gesture.GestureType == KnownGesture.Pan);
        }
Exemple #2
0
    public void OnDrag(NoteAreaDragEvent dragEvent)
    {
        switch (dragAction)
        {
        case DragAction.Move:
            DragDirection dragDirection = GetDragDirection(dragEvent);
            if (dragDirection == DragDirection.Horizontal)
            {
                MoveNotesHorizontal(dragEvent, selectedNotes, true);
            }
            else
            {
                MoveNotesVertical(dragEvent, selectedNotes, true);
            }
            break;

        case DragAction.StretchLeft:
            StretchNotesLeft(dragEvent, selectedNotes);
            break;

        case DragAction.StretchRight:
            StretchNotesRight(dragEvent, selectedNotes, true);
            break;

        default:
            throw new UnityException("Unkown drag action: " + dragAction);
        }

        editorNoteDisplayer.UpdateNotesAndSentences();
    }
Exemple #3
0
 public DragGesture(int buttonIndex = 0, DragDirection direction = DragDirection.Any, bool exclusive = false, float dragThreshold = DefaultDragThreshold)
 {
     ButtonIndex   = buttonIndex;
     Direction     = direction;
     DragThreshold = dragThreshold;
     Exclusive     = exclusive;
 }
        void CheckDirection()
        {
            if (newMousePos.x > (mousePos.x + 1.0f) || newMousePos.x < (mousePos.x + 20.0f))
            {
                if (newMousePos.y < mousePos.y)
                {
                    dragDir = DragDirection.DOWN;
                }
                else if (newMousePos.y > (mousePos.y + 1.0f) || (newMousePos.y < (mousePos.y + 5.0f)))
                {
                    dragDir = DragDirection.UPSHORT;

                    dragVelocity = 5.0f;
                }
            }

            if (newMousePos.x > (mousePos.x + 40.0f))
            {
                if (newMousePos.y < mousePos.y)
                {
                    dragDir = DragDirection.DOWNRIGHT;
                }
                else
                {
                    dragDir = DragDirection.UPRIGHT;
                }
            }

            if (newMousePos.x == mousePos.x && newMousePos.y == mousePos.y)
            {
                dragDir = DragDirection.NONE;

                dragVelocity = .0f;
            }
        }
Exemple #5
0
 void OnPress(bool press)
 {
     if (!press)
     {
         if (_lastDragStrength != 0 || _totalDragOffset != 0)//touch
         {
             DragDirection direction = CalculateDragDirection();
             if (direction != DragDirection.Back)
             {
                 ExchangePrimary(direction);
                 mainPage.pageDirty = true;
             }
             mainPage.TweenBack();
             mainPage.Refresh(_selectedItem, _itemsList);
         }
         else//drag
         {
             mainPage.TweenBack();
         }
         _lastDragStrength = 0;
         _totalDragOffset  = 0;
     }
     else
     {
         mainPage.StopAllCoroutines();
     }
 }
Exemple #6
0
        private void DesktopOnTouchMoved(object sender, EventArgs args)
        {
            if (_startPos == null || !IsDraggable)
            {
                return;
            }

            var position = new Point(Desktop.TouchPosition.X - _startPos.Value.X,
                                     Desktop.TouchPosition.Y - _startPos.Value.Y);

            int newLeft = Left;
            int newTop  = Top;

            if (DragDirection.HasFlag(DragDirection.Horizontal))
            {
                newLeft = position.X;
            }

            if (DragDirection.HasFlag(DragDirection.Vertical))
            {
                newTop = position.Y;
            }

            ConstrainToBounds(ref newLeft, ref newTop);

            Left = newLeft;
            Top  = newTop;
        }
    // 두 블록이 스왑이 가능한지 체크합니다.
    // srcCell = 이동시키고 싶은 셀. dir = 이동하고자하는 방향.
    public void CheckEnableSwapCell(Cell srcCell, DragDirection dir)
    {
        Cell targetCell = null;

        switch (dir)
        {
        case DragDirection.TwentyOClock:
            targetCell = GetTwentyDirectionCell(srcCell);
            break;

        case DragDirection.TwoOClock:
            targetCell = GetTwoDirectionCell(srcCell);
            break;

        case DragDirection.FourOClock:
            targetCell = GetFourDirectionCell(srcCell);
            break;

        case DragDirection.SixOClock:
            targetCell = GetSixDirectionCell(srcCell);
            break;

        case DragDirection.EightOClock:
            targetCell = GetEightDirectionCell(srcCell);
            break;

        case DragDirection.TenOClock:
            targetCell = GetTenDirectionCell(srcCell);
            break;
        }
        CheckSwapCell(srcCell, targetCell);
    }
        public static bool Initialize()
        {
            TouchPanel.EnabledGestures = GestureType.Tap | GestureType.HorizontalDrag | GestureType.VerticalDrag;
            _direction = DragDirection.NONE;

            return true;
        }
    private void OnMouseUp()
    {
        dragDirection = DragDirection.None;
        Vector3 direction = Input.mousePosition - clickPosition;

        direction.Normalize();

        if (direction.x > 0.8f)
        {
            dragDirection = DragDirection.Right;
        }
        else if (direction.x < -0.8f)
        {
            dragDirection = DragDirection.Left;
        }
        else if (direction.y > 0.8f)
        {
            dragDirection = DragDirection.Up;
        }
        else if (direction.y < -0.8f)
        {
            dragDirection = DragDirection.Down;
        }
        Debug.Log("Drag direction: " + dragDirection.ToString());
        MatchController.Instance.PieceWasDragged(this);
    }
Exemple #10
0
    public void Drag()
    {
        if (!m_IsCanDrag)
        {
            return;
        }

        if (!m_IsDrag)
        {
            m_LastMousePosition = Input.mousePosition;
            m_LastMouseDragTime = Time.time;
            m_IsDrag            = true;
            return;
        }

        Vector3 mousePosDiff = Input.mousePosition - m_LastMousePosition;

        float mousePosDiffDir = m_ScrollType == ScrollType.Horizontal ? mousePosDiff.x : mousePosDiff.y;

        if (Mathf.Abs(mousePosDiffDir) / (Time.time - m_LastMouseDragTime) < m_CanScrollSpeed)
        {
            m_IsDrag = false;

            return;
        }
        m_IsCanDrag     = false;
        m_DragDirection = m_ScrollType == ScrollType.Horizontal
                        ? (mousePosDiffDir > 0 ? DragDirection.Left : DragDirection.Right)
                        : (mousePosDiffDir > 0 ? DragDirection.Down : DragDirection.Up);
        ShowItemDir(m_DragDirection);
    }
Exemple #11
0
 public DragEvent(float swipeLength, DragDirection dragDirection, float swipeSpeed, bool isDragEnded, DragInputLayerMask layerMask)
 {
     this.swipeLength   = swipeLength;
     this.dragDirection = dragDirection;
     this.swipeSpeed    = swipeSpeed;
     this.isDragEnded   = isDragEnded;
     this.layerMask     = layerMask;
 }
        private void DragScroll(DragDirection direction)
        {
            bool   isUp   = (direction == DragDirection.Up);
            double offset = Math.Max(0.0, VerticalOffset + (isUp ? -(_dragVelocity * DRAG_INTERVAL) : (_dragVelocity * DRAG_INTERVAL)));

            ScrollToVerticalOffset(offset);
            _dragVelocity = Math.Min(DRAG_MAX_VELOCITY, _dragVelocity + (DRAG_ACCELERATION * DRAG_INTERVAL));
        }
Exemple #13
0
    private void ShowItemDir(DragDirection dragDirection)
    {
        int chooseIndex = (dragDirection == DragDirection.Right || dragDirection == DragDirection.Down)
                        ? m_CurrentItemIndex + 1
                        : m_CurrentItemIndex - 1;

        ShowItem(chooseIndex, false);
    }
Exemple #14
0
 private void Awake()
 {
     _scrollRect    = GetComponent <ScrollRect>();
     _direction     = Direction.Horizontal;
     _dragDirection = DragDirection.None;
     _isCanMove     = false;
     _vecDrag       = Vector2.zero;
 }
Exemple #15
0
    protected void ToggleEmitter()
    {
        Vector3 newPos = emitter.transform.localPosition;
        newPos.y *= -1;
        emitter.transform.localPosition = newPos;

        emitter.startSpeed *= -1;
        directionFacing = (directionFacing == DragDirection.Up ? DragDirection.Down : DragDirection.Up);
    }
 public ItemReorderEventArgs(TreeViewItem item, TreeViewItem oldParent, TreeViewItem newParent,
                             bool copied, DragDirection dragDirection)
 {
     _item          = item;
     _oldParent     = oldParent;
     _newParent     = newParent;
     _copied        = copied;
     _dragDirection = dragDirection;
 }
Exemple #17
0
    public DragDirection CalculateDragDirection()
    {
        int   minDragOffset     = 100;
        int   strengthThreshold = 1;
        float deltaTime         = UnityEngine.Time.realtimeSinceStartup - _lastDragTime;

        if (deltaTime > 0.1f)
        {
            _lastDragStrength = 0;
        }

        DragDirection direction   = DragDirection.Back;
        float         DragPercent = _totalDragOffset / GetComponent <BoxCollider>().size.y;

        if (_lastDragStrength >= strengthThreshold && Mathf.Abs(_totalDragOffset) > minDragOffset)
        {
            if (DragPercent < 0)
            {
                direction = DragDirection.Back;
            }
            else
            {
                direction = DragDirection.Upper;
            }
        }
        else if (_lastDragStrength <= -strengthThreshold && Mathf.Abs(_totalDragOffset) > minDragOffset)
        {
            if (DragPercent > 0)
            {
                direction = DragDirection.Back;
            }
            else
            {
                direction = DragDirection.Lower;
            }
        }
        else
        {
            if (DragPercent > 0.5f)
            {
                direction = DragDirection.Upper;
            }
            else if (DragPercent < -0.5f)
            {
                direction = DragDirection.Lower;
            }
        }
        if (direction == DragDirection.Lower && _currentPageIndex == 0)
        {
            direction = DragDirection.Back;
        }
        else if (direction == DragDirection.Upper && _currentPageIndex + 1 >= PagesCount)
        {
            direction = DragDirection.Back;
        }
        return(direction);
    }
Exemple #18
0
 protected void PlaceEmitter(ParticleSystem emitterObj, Camera camera, DragDirection directionToFace)
 {
     Vector3 localPos = emitterObj.transform.localPosition;
     if (directionFacing != directionToFace){
         ToggleEmitter();
     }
     localPos.y = 13 * (float)directionToFace;
     emitterObj.transform.localPosition = localPos;
 }
Exemple #19
0
        /// <summary>Initializes a new instance of the <see cref="VisualDrag" /> class.</summary>
        /// <param name="control">The control to attach.</param>
        /// <param name="direction">Dragging enabled state.</param>
        public VisualDrag(Control control, DragDirection direction) : this()
        {
            _control   = control;
            _direction = direction;

            if (Enabled)
            {
                AttachEvents();
            }
        }
Exemple #20
0
 private void SetOriginalConstraints()
 {
     MovieViewConstraintTop.Constant = ImageCropViewConstraintTop.Constant =
         ImageCropViewOriginalConstraintTop;
     CollectionViewConstraintHeight.Constant =
         Frame.Height - ImageCropViewOriginalConstraintTop -
         ImageCropView.Frame.Height;
     CollectionViewConstraintTop.Constant = 0;
     DragDirection = DragDirection.Up;
 }
Exemple #21
0
        /// <summary>Initializes a new instance of the <see cref="VisualDrag" /> class.</summary>
        /// <param name="control">The control to attach.</param>
        /// <param name="direction">Dragging enabled state.</param>
        /// <param name="moveCursor">The move Cursor.</param>
        public VisualDrag(Control control, DragDirection direction, Cursor moveCursor)
        {
            _cursorMove = moveCursor;
            _control    = control;
            _direction  = direction;

            if (Enabled)
            {
                AttachEvents();
            }
        }
Exemple #22
0
 public void ChangeBasePositionByDirection(DragDirection direction)
 {
     if (direction == DragDirection.Upper)
     {
         BasePosition = _upperPosition;
     }
     else if (direction == DragDirection.Lower)
     {
         BasePosition = _lowerPosition;
     }
 }
Exemple #23
0
    /// <summary>
    /// Called on touch/mouse moved; performs swap of board items.
    /// </summary>
    /// <param name='position'>Touch/mouse position.</param>
    void MyMouseMove(Vector2 position)
    {
        if (!selObj1)
        {
            return;
        }

        Vector2 dragVec = position - dragOrigin;

        if (dragVec.sqrMagnitude >= dragLength * dragLength)
        {
            // Drag detected, perform item swap.
            int x1 = selObj1.X;
            int y1 = selObj1.Y;

            int x2 = x1;
            int y2 = y1;

            DragDirection dir = GetDragDirFromVec(dragVec);

            switch (dir)
            {
            case DragDirection.Left:
                x2--;
                break;

            case DragDirection.Right:
                x2++;
                break;

            case DragDirection.Up:
                y2++;
                break;

            case DragDirection.Down:
                y2--;
                break;
            }

            if (x2 >= 0 && x2 < boardSizeX && y2 >= 0 && y2 < boardSizeY)
            {
                selObj2 = boardAll[x2, y2];

                // Start swap animation.
                selObj1.AnimateMove(selObj2.transform.position, swapAnimSpeed);
                selObj2.AnimateMove(selObj1.transform.position, swapAnimSpeed);

                gameState = GameState.MoveCheck;
            }

            selObj1.ResetColor();
        }
    }
 public void OnDrag(PointerEventData eventData)
 {
     if (eventData.position.x > lastDragPosition.x)
     {
         dragDirection    = DragDirection.Right;
         lastDragPosition = eventData.position;
     }
     else if (eventData.position.x < lastDragPosition.x)
     {
         dragDirection    = DragDirection.Left;
         lastDragPosition = eventData.position;
     }
 }
Exemple #25
0
    public void EndDrag()
    {
        if (GameManager.instance.touchEnable == false)
        {
            Debug.Log(" Don't Touch !!!");
            return;
        }

        btnUpPos = Input.mousePosition;
        DragDirection dir = GetDirection();

        GameManager.instance.CheckEnableSwapCell(this, dir);
    }
        private void UpdateTouchPosition(Vector2 position)
        {
            dragPosition = position;
            swipeLength  = (initialClickPosition - dragPosition).magnitude;
            swipeTime   += Time.deltaTime;
            Vector2 DragVectioDirection = (dragPosition - initialClickPosition).normalized;

            dragDirection = GetSwipeDirection(DragVectioDirection);
            //Debug.LogError("DragDirection " + dragDirection);
            isDragEnded = false;

            //TODO:Swipe Speed Not Implemented
            Utils.EventAsync(new Events.DragEvent(swipeLength, dragDirection, swipeTime, isDragEnded, dragInputLayerMask));
        }
Exemple #27
0
 private void PannedChanged(CGPoint currentPosition)
 {
     if (DragDirection == DragDirection.Up &&
         currentPosition.Y < _cropBottomY - _dragDiff)
     {
         MovieViewConstraintTop.Constant = ImageCropViewConstraintTop.Constant =
             (nfloat)Math.Max(_imageCropViewMinimalVisibleHeight -
                              ImageCropView.Frame.Height, currentPosition.Y + _dragDiff -
                              ImageCropView.Frame.Height);
         CollectionViewConstraintHeight.Constant =
             (nfloat)Math.Min(Frame.Height - _imageCropViewMinimalVisibleHeight,
                              Frame.Height - ImageCropViewConstraintTop.Constant -
                              ImageCropView.Frame.Height);
     }
     else if (DragDirection == DragDirection.Down &&
              currentPosition.Y > _cropBottomY)
     {
         MovieViewConstraintTop.Constant = ImageCropViewConstraintTop.Constant =
             (nfloat)Math.Min(ImageCropViewOriginalConstraintTop,
                              currentPosition.Y - ImageCropView.Frame.Height);
         CollectionViewConstraintHeight.Constant =
             (nfloat)
             Math.Max(
                 Frame.Height - ImageCropViewOriginalConstraintTop -
                 ImageCropView.Frame.Height,
                 Frame.Height - ImageCropViewConstraintTop.Constant -
                 ImageCropView.Frame.Height);
     }
     else if (DragDirection == DragDirection.Stop &&
              CollectionView.ContentOffset.Y < 0)
     {
         DragDirection = DragDirection.Scroll;
         _imaginaryCollectionViewOffsetStartPosY = currentPosition.Y;
     }
     else if (DragDirection == DragDirection.Scroll)
     {
         MovieViewConstraintTop.Constant         =
             ImageCropViewConstraintTop.Constant =
                 _imageCropViewMinimalVisibleHeight - ImageCropView.Frame.Height +
                 currentPosition.Y - _imaginaryCollectionViewOffsetStartPosY;
         CollectionViewConstraintHeight.Constant =
             (nfloat)
             Math.Max(
                 Frame.Height - ImageCropViewOriginalConstraintTop -
                 ImageCropView.Frame.Height,
                 Frame.Height - ImageCropViewConstraintTop.Constant -
                 ImageCropView.Frame.Height);
     }
 }
    public static float DragableHandle(int id, Rect windowRect, float offset, DragDirection direction)
    {
        int controlID = GUIUtility.GetControlID(id, FocusType.Passive);

        Vector2 positionFilter = Vector2.zero;
        Rect    controlRect    = windowRect;

        switch (direction)
        {
        case DragDirection.Horizontal:
            controlRect = new Rect(controlRect.x + offset - resizeBarHotSpotSize,
                                   controlRect.y,
                                   resizeBarHotSpotSize * 2 + 1.0f,
                                   controlRect.height);
            positionFilter.x = 1.0f;
            break;
        }
        EditorGUIUtility.AddCursorRect(controlRect, MouseCursor.ResizeHorizontal);

        if (GUIUtility.hotControl == 0)
        {
            if (Event.current.type == EventType.MouseDown && controlRect.Contains(Event.current.mousePosition))
            {
                GUIUtility.hotControl = controlID;
                Event.current.Use();
            }
        }
        else if (GUIUtility.hotControl == controlID)
        {
            if (Event.current.type == EventType.MouseDrag)
            {
                Vector2 mousePosition = Event.current.mousePosition;
                Vector2 handleOffset  = new Vector2((mousePosition.x - windowRect.x) * positionFilter.x,
                                                    (mousePosition.y - windowRect.y) * positionFilter.y);
                offset = handleOffset.x + handleOffset.y;
                HandleUtility.Repaint();
            }
            else if (Event.current.type == EventType.MouseUp)
            {
                GUIUtility.hotControl = 0;
            }
        }

        // Debug draw
        // GUI.Box(controlRect, "");

        return(offset);
    }
        private void EndTouch(Vector2 position)
        {
            dragPosition = position;
            swipeLength  = (initialClickPosition - dragPosition).magnitude;
            swipeTime   += Time.deltaTime;
            Vector2 DragVectioDirection = (dragPosition - initialClickPosition).normalized;

            dragDirection = GetSwipeDirection(DragVectioDirection);
            swipeSpeed    = GetSwipeSpeed();

            Debug.LogError("DragDirection End" + dragDirection);
            isDragEnded = true;

            Utils.EventSync(new Events.DragEvent(swipeLength, dragDirection, swipeSpeed, isDragEnded, dragInputLayerMask));
            resetDragEvents();
        }
    public static float DragableHandle(int id, Rect windowRect, float offset, DragDirection direction)
    {
        int controlID = GUIUtility.GetControlID(id, FocusType.Passive);

        Vector2 positionFilter = Vector2.zero;
        Rect controlRect = windowRect;
        switch (direction)
        {
            case DragDirection.Horizontal:
                controlRect = new Rect(controlRect.x + offset - resizeBarHotSpotSize,
                                       controlRect.y,
                                       resizeBarHotSpotSize * 2 + 1.0f,
                                       controlRect.height);
                positionFilter.x = 1.0f;
                break;
        }
        EditorGUIUtility.AddCursorRect(controlRect, MouseCursor.ResizeHorizontal);

        if (GUIUtility.hotControl == 0)
        {
            if (Event.current.type == EventType.MouseDown && controlRect.Contains(Event.current.mousePosition))
            {
                GUIUtility.hotControl = controlID;
                Event.current.Use();
            }
        }
        else if (GUIUtility.hotControl == controlID)
        {
            if (Event.current.type == EventType.MouseDrag)
            {
                Vector2 mousePosition = Event.current.mousePosition;
                Vector2 handleOffset = new Vector2((mousePosition.x - windowRect.x) * positionFilter.x,
                                                   (mousePosition.y - windowRect.y) * positionFilter.y);
                offset = handleOffset.x + handleOffset.y;
                HandleUtility.Repaint();
            }
            else if (Event.current.type == EventType.MouseUp)
            {
                GUIUtility.hotControl = 0;
            }
        }

        // Debug draw
        // GUI.Box(controlRect, "");

        return offset;
    }
Exemple #31
0
        private DragDirectionFlags GetDirectionFlags(DragDirection direction)
        {
            DragDirectionFlags flags = DragDirectionFlags.None;

            switch (direction)
            {
            case DragDirection.None:
                break;

            case DragDirection.NorthWest:
                flags = DragDirectionFlags.North | DragDirectionFlags.West;
                break;

            case DragDirection.North:
                flags = DragDirectionFlags.North;
                break;

            case DragDirection.NorthEast:
                flags = DragDirectionFlags.North | DragDirectionFlags.East;
                break;

            case DragDirection.East:
                flags = DragDirectionFlags.East;
                break;

            case DragDirection.SouthEast:
                flags = DragDirectionFlags.South | DragDirectionFlags.East;
                break;

            case DragDirection.South:
                flags = DragDirectionFlags.South;
                break;

            case DragDirection.SouthWest:
                flags = DragDirectionFlags.South | DragDirectionFlags.West;
                break;

            case DragDirection.West:
                flags = DragDirectionFlags.West;
                break;

            default:
                break;
            }

            return(flags);
        }
Exemple #32
0
    public void OnEndDrag(PointerEventData eventData)
    {
        // 拖拽方向
        _dragDirection = JudgeDragDirection(_vecDrag);
        // 目标下标
        int finalIndex = JudgeTargetIndex(_posList, _dragDirection);

        if (finalIndex != -1)
        {
            _isCanMove    = true;
            _targetHorPos = _posList[finalIndex];
        }
        else
        {
            _isCanMove = false;
        }
    }
Exemple #33
0
        private Cursor GetCursorFromPoint(Point point)
        {
            DragDirection direction = GetDragDirection(point);
            Cursor        cursor    = null;

            switch (direction)
            {
            case DragDirection.NorthWest:
                cursor = Cursors.SizeNWSE;
                break;

            case DragDirection.North:
                cursor = Cursors.SizeNS;
                break;

            case DragDirection.NorthEast:
                cursor = Cursors.SizeNESW;
                break;

            case DragDirection.East:
                cursor = Cursors.SizeWE;
                break;

            case DragDirection.SouthEast:
                cursor = Cursors.SizeNWSE;
                break;

            case DragDirection.South:
                cursor = Cursors.SizeNS;
                break;

            case DragDirection.SouthWest:
                cursor = Cursors.SizeNESW;
                break;

            case DragDirection.West:
                cursor = Cursors.SizeWE;
                break;

            default:
                cursor = Cursors.Arrow;
                break;
            }

            return(cursor);
        }
        public static void OnUpdate()
        {
            _currTState = TouchPanel.GetState();

            while (TouchPanel.IsGestureAvailable)
            {
                GestureSample gesture = TouchPanel.ReadGesture();

                switch (gesture.GestureType)
                {
                    case GestureType.HorizontalDrag:
                        Console.WriteLine("Horizontal Drag: " + gesture.Delta);

                        if (gesture.Delta.X > 0)
                            _direction = DragDirection.RIGHT;

                        else if (gesture.Delta.X < 0)
                            _direction = DragDirection.LEFT;

                        else
                            _direction = DragDirection.NONE;

                        break;

                    case GestureType.VerticalDrag:
                        Console.WriteLine("Vertical Drag: " + gesture.Delta);

                        if (gesture.Delta.Y > 0)
                            _direction = DragDirection.DOWN;

                        else if (gesture.Delta.Y < 0)
                            _direction = DragDirection.UP;

                        else
                            _direction = DragDirection.NONE;

                        break;

                    default:
                        _direction = DragDirection.NONE;
                        break;
                }
            }
        }
    void Update()
    {
        Vector3 mouseWorldPos = camera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, camera.nearClipPlane));


        if (Input.GetMouseButtonDown(0))
        {
            initMousePosition = mouseWorldPos;
            lastMousePosition = mouseWorldPos;

            currentState = State.Idle;
        }

        if (Input.GetMouseButton(0) && initMousePosition != Vector3.negativeInfinity)
        {
            if (Vector3.Distance(mouseWorldPos, initMousePosition) > dragDiff && currentState == State.Idle)
            {
                Vector3 diff  = mouseWorldPos - initMousePosition;
                float   vDiff = Mathf.Abs(diff.y);
                float   hDiff = Mathf.Abs(diff.x);
                dragDirection = (vDiff > hDiff) ? DragDirection.Vertical : DragDirection.Horizontal;

                currentState = State.Drag;
            }
            else if (currentState == State.Drag)
            {
                //Debug.Log(mouseWorldPos +", "+ lastMousePosition);

                moveDelta = (mouseWorldPos - lastMousePosition);
                DragObject(moveDelta * dragPower, dragDirection);
            }

            lastMousePosition = mouseWorldPos;
        }

        if (Input.GetMouseButtonUp(0))
        {
            initMousePosition = Vector3.negativeInfinity;
            currentState      = State.Idle;
        }
    }
 private void DragScroll(DragDirection direction)
 {
     bool isUp = (direction == DragDirection.Up);
     double offset = Math.Max(0.0, VerticalOffset + (isUp ? -(_dragVelocity * s_dragInterval) : (_dragVelocity * s_dragInterval)));
     ScrollToVerticalOffset(offset);
     _dragVelocity = Math.Min(s_dragMaxVelocity, _dragVelocity + (s_dragAcceleration * s_dragInterval));
 }
    //Input used in Update vs FixedUpdate
    void Update()
    {
        if (Input.touchCount > 0) {

            Touch touch = Input.touches [0];

            switch (touch.phase) {
            //if touch began
            case TouchPhase.Began:
                couldBeDrag = true;
                lastDrag = DragDetectorScript.DragDirection.None;

                lastDragTime = 0;

                couldBeDrag = true;

                startPos = touch.position;

                startTime = Time.time;

                break;

            //if touch moved
            case TouchPhase.Moved:
                if(couldBeDrag)
                {
                    float dragDist = (new Vector3(0, touch.position.y, 0) - new Vector3(0, startPos.y, 0)).magnitude;

                    //took out comfortZone
        //					if (Mathf.Abs (touch.position.x - startPos.x) > comfortZone) {
        //
        //						Debug.Log ("Not a swipe. Swipe strayed " + (int)Mathf.Abs (touch.position.x - startPos.x) +
        //
        //	                                  "px which is " + (int)(Mathf.Abs (touch.position.x - startPos.x) - comfortZone) +
        //
        //	                                  "px outside the comfort zone.");
        //
        //						couldBeDrag = false;
        //
        //					}
        //					else if (dragDist > minDragDist)
                    if(dragDist > minDragDist)
                    {
                        float dragValue = Mathf.Sign (touch.position.y - startPos.y);
                        if(dragValue > 0)
                        {
                            if(lastDrag == DragDirection.Down || lastDrag == DragDirection.None)
                            {
                                lastDrag = DragDetectorScript.DragDirection.Up;
                                player.setGravityUp(true);
                                player.setGravityButton(true);
                            }

                        }
                        else if(dragValue < 0)
                        {
                            if(lastDrag == DragDirection.Up || lastDrag == DragDirection.None)
                            {
                                lastDrag = DragDetectorScript.DragDirection.Down;
                                player.setGravityUp(false);
                                player.setGravityButton(true);
                            }
                        }
                        startPos = touch.position;
                    }
                }

                break;

            case TouchPhase.Stationary:
                if(couldBeDrag)
                {
                    startPos = touch.position;
                }
                break;

            //if touch ended
            case TouchPhase.Ended:

                if (couldBeDrag) {

                    float swipeTime = Time.time - startTime;

                    float dragDist = (new Vector3 (0, touch.position.y, 0) - new Vector3 (0, startPos.y, 0)).magnitude;

                    if ((swipeTime < maxDragTime) && (dragDist > minDragDist)) {

                        // It's a swiiiiiiiiiiiipe!

                        //float dragValue = Mathf.Sign (touch.position.y - startPos.y);

                        // If the swipe direction is positive, it was an upward swipe.

                        // If the swipe direction is negative, it was a downward swipe.

        //						if (dragValue > 0)
        //
        //							lastDrag = DragDetectorScript.DragDirection.Up;
        //						else if (dragValue < 0)
        //
        //							lastDrag = DragDetectorScript.DragDirection.Down;
        //						if(dragValue > 0)
        //						{
        //							lastDrag = DragDetectorScript.DragDirection.Up;
        //							player.setGravityUp(true);
        //							player.setGravityButton(true);
        //
        //						}
        //						else if(dragValue < 0)
        //						{
        //							lastDrag = DragDetectorScript.DragDirection.Down;
        //							player.setGravityUp(false);
        //							player.setGravityButton(true);
        //						}

                        // Set the time the last swipe occured, useful for other scripts to check:

                        lastDragTime = Time.time;

                        //Debug.Log("Found a swipe!  Direction: " + lastDrag);

                    }

                }

                break;

            }

        }
    }
		public TouchDragTrigger(DragDirection direction = DragDirection.Free)
		{
			Direction = direction;
		}
Exemple #39
0
 private void DragScroll(DragDirection direction)
 {
     bool isUp = (direction == DragDirection.Up);
     double offset = Math.Max(0.0, VerticalOffset + (isUp ? -(_dragVelocity * DRAG_INTERVAL) : (_dragVelocity * DRAG_INTERVAL)));
     ScrollToVerticalOffset(offset);
     _dragVelocity = Math.Min(DRAG_MAX_VELOCITY, _dragVelocity + (DRAG_ACCELERATION * DRAG_INTERVAL));
 }