//Force movement from objects like treadmills
    public void ForceDirection(Vector3 direction)
    {
        DraggedDirection newDirection = DraggedDirection.Up;

        Debug.Log("Given the following direction vector: " + direction.ToString());

        if (direction.x > 1.0f)
        {
            newDirection = DraggedDirection.Right;
        }
        if (direction.x < -1.0f)
        {
            newDirection = DraggedDirection.Left;
        }
        if (direction.z > 1.0f)
        {
            newDirection = DraggedDirection.Up;
        }
        if (direction.z < -1.0f)
        {
            newDirection = DraggedDirection.Down;
        }

        forcedDirection  = newDirection;
        forcingDirection = true;
    }
 void dashing() // function that control dashing
 {
     if (currentDirection != DraggedDirection.None)
     {
         if (dashTime <= 0) // If dash is over set direction to none
         {
             currentDirection = DraggedDirection.None;
             dashTime         = startingDashTime;
             rb.velocity      = Vector2.zero;
         }
         else // if not over , deduct time passed from dashtime and find the direction of the dash
         {
             dashTime -= Time.deltaTime;
             if (currentDirection == DraggedDirection.Left)
             {
                 rb.velocity = Vector2.left * dashSpeed;
             }
             else if (currentDirection == DraggedDirection.Right)
             {
                 rb.velocity = Vector2.right * dashSpeed;
             }
             else if (currentDirection == DraggedDirection.Down)
             {
                 rb.velocity = Vector2.down * dashSpeed;
             }
             else if (currentDirection == DraggedDirection.Up)
             {
                 rb.velocity = Vector2.up * dashSpeed;
             }
         }
     }
 }
示例#3
0
    public void Drag()
    {
        if (Input.touches.Length > 0)
        {
            Touch t = Input.GetTouch(0);
            if (t.phase == TouchPhase.Began)
            {
                startPos  = new Vector2(t.position.x / (float)Screen.width, t.position.y / (float)Screen.width);
                startTime = Time.time;
                print("START");
            }
            if (t.phase == TouchPhase.Ended)
            {
                if (Time.time - startTime > MAX_SWIPE_TIME)                 // press too long
                {
                    return;
                }

                Vector2 endPos = new Vector2(t.position.x / (float)Screen.width, t.position.y / (float)Screen.width);

                Vector2 swipe = new Vector2(endPos.x - startPos.x, endPos.y - startPos.y);

                if (swipe.magnitude < MIN_SWIPE_DISTANCE)                 // Too short swipe
                {
                    return;
                }

                if (Mathf.Abs(swipe.x) > Mathf.Abs(swipe.y))
                {
                    if (swipe.x > 0)
                    {
                        swipeDir = DraggedDirection.RIGHT;
                    }
                    else
                    {
                        swipeDir = DraggedDirection.LEFT;
                    }
                }
                else
                {
                    if (swipe.y > 0)
                    {
                        swipeDir = DraggedDirection.UP;
                    }
                    else
                    {
                        swipeDir = DraggedDirection.DOWN;
                    }
                }
                print("END");
                print(swipeDir);
            }
        }
    }
示例#4
0
 void MoveCanGat(DraggedDirection direction)
 {
     if (direction == DraggedDirection.Up)
     {
         Next();
     }
     if (direction == DraggedDirection.Down)
     {
         Pre();
     }
 }
示例#5
0
    public override void OnEndDrag(PointerEventData eventData)
    {
        Vector3 dragVectorDirection = (eventData.position - eventData.pressPosition).normalized;

        DraggedDirection myDirection = GetDragDirection(dragVectorDirection);

        if (myDirection == DraggedDirection.Left)
        {
            controller.Instance.Randomword();
        }
        else if (myDirection == DraggedDirection.Right)
        {
            controller.Instance.ReverseOpenPaper();
        }
    }
示例#6
0
    private DraggedDirection GetDragDirection(Vector3 dragVector)
    {
        float            positiveX = Mathf.Abs(dragVector.x);
        float            positiveY = Mathf.Abs(dragVector.y);
        DraggedDirection draggedDir;

        if (positiveX > positiveY)
        {
            draggedDir = (dragVector.x > 0) ? DraggedDirection.RIGHT : DraggedDirection.LEFT;
        }
        else
        {
            draggedDir = (dragVector.y > 0) ? DraggedDirection.UP : DraggedDirection.DOWN;
        }
        swipeDir = draggedDir;
        print(draggedDir);
        return(draggedDir);
    }
示例#7
0
        public static void SwipeObject(DraggedDirection draggedDirrection)
        {
            GameController.inst.StopMoving();

            switch (draggedDirrection)
            {
            case DraggedDirection.Left:
                GameController.inst.moveLeft = true;
                break;

            case DraggedDirection.Right:
                GameController.inst.moveRight = true;
                break;

            default: break;
            }

            GameController.inst.RunMoveTimer();
        }
 void checkTouches()
 {
     foreach (Touch touch in Input.touches)
     {
         if (touch.phase == TouchPhase.Began)
         {
             fingerDownPosition = touch.position;
         }
         if (touch.phase == TouchPhase.Ended)
         {
             fingerUpPosition = touch.position;
             Vector2 dragVector = fingerUpPosition - fingerDownPosition;
             if (dragVector.magnitude > 10) // checks that it is not a touch
             {
                 dragVector       = dragVector.normalized;
                 currentDirection = GetDraggedDirection(dragVector);
             }
         }
     }
 }
    protected void MoveAndSnapToGrid()
    {
        //Reset targetLerp position when needed
        if (positionT >= 1.0f)
        {
            preTargetPosition = transform.position;
        }


        //Force a direction?
        if (forcingDirection)
        {
            currentDirection = forcedDirection;
        }

        //Every update check the direction and update the velocity. Also rotate to that direction.
        switch (currentDirection)
        {
        case DraggedDirection.Up:

            if (positionT >= 1.0f)
            {
                positionT = 0.0f; targetPosition = transform.position + (new Vector3(0.0f, 0.0f, 1.0f));
            }
            targetRotation = Quaternion.Euler(0.0f, 90.0f, 0.0f);
            timeRotating   = 0.0f;
            break;

        case DraggedDirection.Down:

            if (positionT >= 1.0f)
            {
                positionT = 0.0f; targetPosition = transform.position + (new Vector3(0.0f, 0.0f, -1.0f));
            }
            targetRotation = Quaternion.Euler(0.0f, 270.0f, 0.0f);
            timeRotating   = 0.0f;
            if (positionT >= 1.0f)
            {
                positionT = 0.0f;
            }
            break;

        case DraggedDirection.Left:
            if (positionT >= 1.0f)
            {
                positionT = 0.0f; targetPosition = transform.position + (new Vector3(-1.0f, 0.0f, 0.0f));
            }
            targetRotation = Quaternion.Euler(0.0f, 0.0f, 0.0f);
            timeRotating   = 0.0f;
            break;

        case DraggedDirection.Right:
            if (positionT >= 1.0f)
            {
                positionT = 0.0f; targetPosition = transform.position + (new Vector3(1.0f, 0.0f, 0.0f));
            }
            targetRotation = Quaternion.Euler(0.0f, 180.0f, 0.0f);
            timeRotating   = 0.0f;
            if (positionT >= 1.0f)
            {
                positionT = 0.0f;
            }
            break;
        }


        //transform.position = AlignToGrid(transform.position);
    }
示例#10
0
        private void Update()
        {
            currentDirection = DraggedDirection.None;
            if (Input.touches.Length > 0)
            {
                Touch t = Input.GetTouch(0);
                if (t.phase == TouchPhase.Began)
                {
                    startPos  = new Vector2(t.position.x / (float)Screen.width, t.position.y / (float)Screen.width);
                    startTime = Time.time;
                }
                if (t.phase == TouchPhase.Ended)
                {
                    if (Time.time - startTime > MAX_SWIPE_TIME) // press too long
                    {
                        return;
                    }

                    Vector2 endPos = new Vector2(t.position.x / (float)Screen.width, t.position.y / (float)Screen.width);

                    Vector2 swipe = new Vector2(endPos.x - startPos.x, endPos.y - startPos.y);

                    if (swipe.magnitude < MIN_SWIPE_DISTANCE) // Too short swipe
                    {
                        return;
                    }

                    if (Mathf.Abs(swipe.x) > Mathf.Abs(swipe.y))
                    { // Horizontal swipe
                        if (swipe.x > 0)
                        {
                            if (currentDirection != DraggedDirection.Left)
                            {
                                currentDirection = DraggedDirection.Right;
                            }
                        }
                        else
                        {
                            if (currentDirection != DraggedDirection.Right)
                            {
                                currentDirection = DraggedDirection.Left;
                            }
                        }
                    }
                    else
                    { // Vertical swipe
                        if (swipe.y > 0)
                        {
                            if (currentDirection != DraggedDirection.Down)
                            {
                                currentDirection = DraggedDirection.Up;
                            }
                        }
                        else
                        {
                            if (currentDirection != DraggedDirection.Up)
                            {
                                currentDirection = DraggedDirection.Down;
                            }
                        }
                    }
                }
            }
            //for editor
            if (Input.GetKeyDown(KeyCode.RightArrow))
            {
                currentDirection = DraggedDirection.Right;
            }
            else if (Input.GetKeyDown(KeyCode.LeftArrow))
            {
                currentDirection = DraggedDirection.Left;
            }
            else if (Input.GetKeyDown(KeyCode.DownArrow))
            {
                currentDirection = DraggedDirection.Down;
            }
            else if (Input.GetKeyDown(KeyCode.UpArrow))
            {
                currentDirection = DraggedDirection.Up;
            }
            checkMove();
        }
    // get second position when exiting button zone
    public void OnPointerExit(PointerEventData eventData)
    {
        dragVectorDirectionExit = eventData.position;

        // calculate and normalize direction vector
        Vector3          dragVectorDirection = (dragVectorDirectionExit - dragVectorDirectionEnter).normalized;
        DraggedDirection move = GetDragDirection(dragVectorDirection);


        // first level of UI
        if (levelUI == 1)
        {
            // limit cursor movement
            switch (move)
            {
            // cursor can only move four times to the right, etc
            case DraggedDirection.Right:
                if (countRight > 0 && countRight < 4)
                {
                    cursor.transform.position += Vector3.right * speed * Time.deltaTime;
                    countRight++;
                }
                break;

            case DraggedDirection.Left:
                if (countRight > 1 && countRight < 5)
                {
                    cursor.transform.position += Vector3.left * speed * Time.deltaTime;
                    countRight--;
                }
                break;

            case DraggedDirection.Down:
                if (countDown > 0 && countDown < 2)
                {
                    cursor.transform.position += Vector3.down * speed * Time.deltaTime;
                    countDown++;
                }
                break;

            case DraggedDirection.Up:
                if (countDown > 1 && countDown < 3)
                {
                    cursor.transform.position += Vector3.up * speed * Time.deltaTime;
                    countDown--;
                }
                break;

            default:
                break;
            }
        }
        // second level of UI (reached through click)
        else if (levelUI == 2)
        {
            // limit cursor movement
            switch (move)
            {
            // cursor can only move four times to the right, etc
            case DraggedDirection.Right:
                if (countRight > 0 && countRight < 4)
                {
                    cursor.transform.position += Vector3.right * speed * Time.deltaTime;
                    countRight++;
                }
                break;

            case DraggedDirection.Left:
                if (countRight > 1 && countRight < 5)
                {
                    cursor.transform.position += Vector3.left * speed * Time.deltaTime;
                    countRight--;
                }
                break;;

            default:
                break;
            }
        }
        else
        {
            return;
        }
        screenCount++;
    }