Beispiel #1
0
    public void Rotate(SwipeAction swipeAction)
    {
        int multiplier = swipeAction.Direction == SwipeDirection.Left ? -1 : 1;
        var targetRot  = transform.rotation * Quaternion.AngleAxis(swipeAction.SwipeValue * multiplier * _speed * Time.deltaTime, transform.up);

        _targetAngles = targetRot.eulerAngles;
        //HACK: Dirty solution
        if (_targetAngles.y > 300f)
        {
            _targetAngles.y = _targetAngles.y - 360;
        }

        if (_targetAngles.y > ROTATION_LIMIT)
        {
            _targetAngles.y       = ROTATION_LIMIT;
            transform.eulerAngles = _targetAngles;
        }
        else if (_targetAngles.y < -ROTATION_LIMIT)
        {
            _targetAngles.y       = -ROTATION_LIMIT;
            transform.eulerAngles = _targetAngles;
        }

        transform.DOKill();
        transform.DORotate(_targetAngles, 0.1f);

        OnCameraRotationChange.Invoke(_targetAngles.y);
    }
Beispiel #2
0
 void HandleSwipe(SwipeAction swipeAction)
 {
     Debug.LogFormat("HandleSwipe: {0}", swipeAction);
     if (player == null)
     {
         player = GameObject.FindGameObjectWithTag("Player").GetComponent <Player>();
     }
     else if (swipeAction.direction == SwipeDirection.UpRight || swipeAction.direction == SwipeDirection.DownLeft)
     {
         player.currentState = BLOCKSTATES.BLOCKLEFT;
     }
     else if (swipeAction.direction == SwipeDirection.Right || swipeAction.direction == SwipeDirection.Left)
     {
         player.currentState = BLOCKSTATES.BLOCKHIGH;
     }
     else if (swipeAction.direction == SwipeDirection.DownRight || swipeAction.direction == SwipeDirection.UpLeft)
     {
         player.currentState = BLOCKSTATES.BLOCKRIGHT;
     }
     else
     {
         player.currentState = BLOCKSTATES.NOBLOCK;
     }
     Debug.LogFormat("Block: {0}", player.currentState);
 }
Beispiel #3
0
 void HandleSwipe(SwipeAction swipeAction)
 {
     //Debug.LogFormat("HandleSwipe: {0}", swipeAction);
     if (swipeAction.direction == SwipeDirection.Up || swipeAction.direction == SwipeDirection.UpRight)
     {
         // move up
         // if (OurPlayer != null)
         //     OurPlayer.MovePlayerUp();
     }
     else if (swipeAction.direction == SwipeDirection.Right || swipeAction.direction == SwipeDirection.DownRight)
     {
         // move right
         // if (OurPlayer != null)
         //     OurPlayer.MovePlayerRight();
     }
     else if (swipeAction.direction == SwipeDirection.Down || swipeAction.direction == SwipeDirection.DownLeft)
     {
         // move down
         // if (OurPlayer != null)
         //     OurPlayer.MovePlayerDown();
     }
     else if (swipeAction.direction == SwipeDirection.Left || swipeAction.direction == SwipeDirection.UpLeft)
     {
         // move left
         // if (OurPlayer != null)
         //     OurPlayer.MovePlayerLeft();
     }
 }
Beispiel #4
0
    void HandleTap(SwipeAction swipeAction)
    {
        if (player == null)
        {
            player = GameObject.FindGameObjectWithTag("Player").GetComponent <Player>();
        }
        EventManager.PlayerTap(player.gameObject, new PlayerEventArgs(player));

        Debug.LogFormat("HandleLongPress: {0}", swipeAction);
    }
    public void Init()
    {
        _swipeDetector          = new SwipeDetector();
        _swipeDetector.OnSwipe += SwipeDetector_OnSwipe;

        _swipeAction = new SwipeAction();

        //TODO: Remove this. Input should be enabled from game controller.
        EnableInput();
    }
    private void SwipeDetection(SwipeAction swipeAction)
    {
        if (useDebug)
        {
            switch (swipeAction.direction)
            {
            case SwipeDirection.None:
                DebugText.text = " ";
                break;

            case SwipeDirection.Hold:
                DebugText.text = "Hold";
                break;

            case SwipeDirection.Tap:
                DebugText.text = "Tap";
                break;

            case SwipeDirection.Up:
                DebugText.text = "Swipe Up";
                break;

            case SwipeDirection.UpRight:
                DebugText.text = "Swipe Up Right";
                break;

            case SwipeDirection.Right:
                DebugText.text = "Swipe Right";
                break;

            case SwipeDirection.DownRight:
                DebugText.text = "Swipe Down Right";
                break;

            case SwipeDirection.Down:
                DebugText.text = "Swipe Down";
                break;

            case SwipeDirection.DownLeft:
                DebugText.text = "Swipe Down Left";
                break;

            case SwipeDirection.Left:
                DebugText.text = "Swipe Left";
                break;

            case SwipeDirection.UpLeft:
                DebugText.text = "Swipe Up Left";
                break;
            }
        }
    }
    private void HandleSwipe(SwipeAction swipeAction)
    {
        if (!CanInteract())
        {
            return;
        }
        if (swipeAction.direction == SwipeDirection.None)
        {
            return;
        }

        gridManager.RotateSelected(swipeAction.direction == SwipeDirection.Clockwise);
    }
    private void HandleTap(SwipeAction swipeAction)
    {
        if (!CanInteract())
        {
            return;
        }

        Collider2D collider = swipeAction.collider;

        if (collider != null && collider.transform.tag == "Hex")
        {
            gridManager.SelectGroup(swipeAction.collider, swipeAction.endWPPosition);
        }
    }
Beispiel #9
0
    void HandleSwipe(SwipeAction swipeAction)
    {
        //Debug.LogFormat("HandleSwipe: {0}", swipeAction);
        if (swipeAction.direction == SwipeDirection.Up || swipeAction.direction == SwipeDirection.UpRight)
        {
            // move up
            //       if (OurPlayer != null)
            //         OurPlayer.MovePlayerUp();
            Debug.Log("up");
        }
        else
        if (swipeAction.direction == SwipeDirection.Right || swipeAction.direction == SwipeDirection.DownRight)
        {
            float step = 0;
            // move right
            //         if (OurPlayer != null)
            //           OurPlayer.MovePlayerRight();

            /*          while (step<5f)
             *        {
             *            transform.position += new Vector3(0.2f, 0f, 0.0f);
             *            step += 0.2f;
             *        }
             *        step = 0;*/

            //  MoveFromTo(transform, transform.position, (transform.position + new Vector3(5,0,0)), 5f);
            Debug.Log("right");
        }
        else if (swipeAction.direction == SwipeDirection.Down || swipeAction.direction == SwipeDirection.DownLeft)
        {
            // move down
            //        if (OurPlayer != null)
            //          OurPlayer.MovePlayerDown();
            Debug.Log("down");
        }
        else if (swipeAction.direction == SwipeDirection.Left || swipeAction.direction == SwipeDirection.UpLeft)
        {
            // move left
            //    if (OurPlayer != null)
            //       OurPlayer.MovePlayerLeft();
            Debug.Log("left");
            transform.position += new Vector3(-5f, 0f, 0.0f);
        }
    }
Beispiel #10
0
        public System.Windows.Input.ICommand GetMoveSectionCmd(CommonBaseVM vm, IOrdered line)
        {
            return(new Command((arg) =>
            {
                line.TimeStamp = DateTime.Now;

                Task.Factory.StartNew(() => Task.Delay(3000))
                .ContinueWith((t, x) =>
                {
                    if ((DateTime.Now.Subtract((x as IOrdered).TimeStamp).TotalSeconds > 3))
                    {
                        (x as IOrdered).OrderImageName = "empty.png";
                    }
                },
                              line);


                SwipeAction swipe = (arg as SwipeAction?).Value;
                SwipeType swipeType = SwipeType.None;
                if ((swipe.Type & SwipeType.Up) != 0 || (swipe.Type & SwipeType.Left) != 0)
                {
                    line.OrderImageName = "up.png";
                    swipeType = SwipeType.Up;
                }
                else if ((swipe.Type & SwipeType.Down) != 0 || (swipe.Type & SwipeType.Right) != 0)
                {
                    line.OrderImageName = "down.png";
                    swipeType = SwipeType.Down;
                }
                else
                {
                    line.OrderImageName = "empty.png";
                }

                if (swipe.Finished)
                {
                    vm.Order.MoveOutputLine(line, -1, swipeType);
                    line.OrderImageName = "empty.png";
                }

                vm.RaiseChanges();
            }));
        }
Beispiel #11
0
    void HandleSwipe(SwipeAction swipeAction)
    {
        //Debug.LogFormat("HandleSwipe: {0}", swipeAction);

        if (swipeAction.touchPhase == TouchPhase.Began)
        {
            previousTouchPosition = swipeAction.startPosition;
        }

        var incrementalSwipe = swipeAction.endPosition - previousTouchPosition;

        previousTouchPosition = swipeAction.endPosition;
        incrementalSwipe.Normalize();
        horizontalAxis = incrementalSwipe.x;
        verticalAxis   = incrementalSwipe.y;

        if (swipeAction.touchPhase == TouchPhase.Ended)
        {
            verticalAxis   = 0;
            horizontalAxis = 0;
        }
    }
 private void EndTouchPrimary(InputAction.CallbackContext context)
 {
     touchEndPosition = ScreenToWorld(touchPosition.ReadValue <Vector2>());
     touchEndTime     = (float)context.time;
     if ((touchEndTime - touchStartTime) <= MAX_SWIPE_TIME)
     {
         float deltaY = touchEndPosition.y - touchStartPosition.y;
         float deltaX = touchEndPosition.x - touchStartPosition.x;
         float magY   = Mathf.Abs(deltaY);
         float magX   = Mathf.Abs(deltaX);
         if (magY > MIN_SWIPE_DIST && magY >= magX)
         {
             if (deltaY > 0 && canPlayerMove())
             {
                 jump();
                 latestSwipe = SwipeAction.Up;
             }
             else
             {
                 slide();
                 latestSwipe = SwipeAction.Down;
             }
         }
         else if (magX > MIN_SWIPE_DIST && magX > magY)
         {
             if (deltaX > 0)
             {
                 moveRight();
                 latestSwipe = SwipeAction.Right;
             }
             else
             {
                 moveLeft();
                 latestSwipe = SwipeAction.Left;
             }
         }
     }
 }
Beispiel #13
0
    void HandleSwipe(SwipeAction swipeAction)
    {
        ////Debug.LogFormat("HandleSwipe: {0}", swipeAction);
        //if (swipeAction.direction == SwipeDirection.Up || swipeAction.direction == SwipeDirection.UpRight)
        //{
        //    Debug.Log("up");
        //}
        //else if (swipeAction.direction == SwipeDirection.Right || swipeAction.direction == SwipeDirection.DownRight)
        //{
        //    if (leaderboard.activeInHierarchy&&!kelu)
        //    {
        //        kelu = true;
        //        leaderboard.GetComponent<Animator>().Play("LederIn");
        //    }
        //    else
        //    {
        //        kelu = true;
        //        leaderboard.SetActive(true);
        //    }

        //    Debug.Log("right");
        //}
        //else if (swipeAction.direction == SwipeDirection.Down || swipeAction.direction == SwipeDirection.DownLeft)
        //{
        //    Debug.Log("down");
        //}
        //else if (swipeAction.direction == SwipeDirection.Left || swipeAction.direction == SwipeDirection.UpLeft)
        //{
        //    // move left
        //    if (kelu)
        //    {
        //        kelu = false;
        //        leaderboard.GetComponent<Animator>().Play("LeaderOut");
        //    }

        //    Debug.Log("left");
        //}
    }
 private void HoldRotation(SwipeAction swipeAction)
 {
     currentAction = swipeAction;
     heldDown      = true;
 }
Beispiel #15
0
    private void DetectSwipeAction(SwipeAction swipeAction)
    {
        switch (swipeAction.direction)
        {
        case SwipeDirection.Up:
            break;

        case SwipeDirection.UpRight:
            break;

        case SwipeDirection.Right:
            break;

        case SwipeDirection.DownRight:
            break;

        case SwipeDirection.Down:
            break;

        case SwipeDirection.DownLeft:
            break;

        case SwipeDirection.Left:
            break;

        case SwipeDirection.UpLeft:
            break;
        }

        //Vector3 angleDir = playerPosition - mainCamera.position;
        //Vector3 angleForward = mainCamera.forward;

        //float angle = Vector3.Angle(angleDir, angleForward);

        // Find the players current position
        Vector3 playerPosition = transform.position;
        // Convert screen direction to transform local direction, then normalise to get direction
        Vector3 facingDirection = new Vector3(swipeAction.clampedDirection.x, 0, swipeAction.clampedDirection.y).normalized;
        // Rotate the vector by angle, the * by the original direction
        Vector3 rotatedVector = Quaternion.AngleAxis(45, Vector3.up) * facingDirection;
        // Set the final position = the original position + the rotated facing direction
        Vector3 finalPos = playerPosition + rotatedVector;

#if UNITY_EDITOR
        Vector3 debugVectorForward = Quaternion.AngleAxis(45, Vector3.up) * Vector3.forward;
        if (finalPos - transform.position == debugVectorForward)
        {
            Debug.DrawLine(transform.position, finalPos, Color.red, 5);
        }
        else
        {
            Debug.DrawLine(transform.position, finalPos, Color.blue, 5);
        }
#endif

        NNConstraint constraint = NNConstraint.None;

        // Constrain the search to walkable nodes only
        constraint.constrainWalkability = true;
        constraint.walkable             = true;

        // Constrain the search to only nodes with tag 1 or tag 2
        constraint.constrainTags = true;
        constraint.tags          = (1 << 1) | (1 << 2);

        NNInfo    info      = AstarPath.active.GetNearest(finalPos);
        GraphNode node      = info.node;
        Vector3   nodePos   = (Vector3)node.position;
        Vector3   finalNode = new Vector3(finalPos.x, nodePos.y, finalPos.z);

        //var dist = Vector3Int.Distance(new Vector3Int(node.position.x, node.position.y, node.position.z), new Vector3Int((int)finalPos.x, node.position.y, (int)finalPos.z)));

        if (nodePos == finalNode)
        {
            if (node.Walkable)
            {
                transform.DOMove(finalPos, moveSpeed, false);
                transform.DOLookAt(finalPos, 0.2f, AxisConstraint.Y, Vector2.up);
            }
            else
            {
                Debug.LogError("Shouldnt Walk Here!");
            }
        }

        //GameManager.Instance.UpdateWorldTurn();
    }
Beispiel #16
0
 private void DetectTapAction(SwipeAction swipeAction)
 {
 }
Beispiel #17
0
 private void DetectHoldAction(SwipeAction swipeAction)
 {
 }
Beispiel #18
0
 void HandleSwipe(SwipeAction swipeAction)
 {
     // if a block has been swiped through and is in the sweetspot, check the direction to see if it needs to be destroyed
     if (gameObject.GetComponent <Block>().swiped)
     {
         // if its in the sweetspot & has been flipped to the correct orientation, proceed
         if (gameObject.GetComponent <Block>().inSweetSpot&& FindObjectOfType <FlipManager>().flipStatusMatching)
         {
             if (swipeAction.direction == SwipeDirection.Up)
             {
                 direction = "up";
                 if (block != null)
                 {
                     if (block.checkType(direction))
                     {
                         Instantiate(blockHalf1, new Vector3(gameObject.transform.position.x, gameObject.transform.position.y + 1, 0), Quaternion.identity);
                         Instantiate(blockHalf2, new Vector3(gameObject.transform.position.x, gameObject.transform.position.y - 1, 0), Quaternion.identity);
                         Destroy(gameObject);
                         GameObject.Find("ScoringSystem").GetComponent <ScoringSystem>().increaseScore();
                     }
                 }
             }
             else if (swipeAction.direction == SwipeDirection.UpRight)
             {
                 direction = "upright";
                 if (block != null)
                 {
                     if (block.checkType(direction))
                     {
                         Instantiate(blockHalf1, new Vector3(gameObject.transform.position.x - 1, gameObject.transform.position.y + 1, 0), Quaternion.identity);
                         Instantiate(blockHalf2, new Vector3(gameObject.transform.position.x + 1, gameObject.transform.position.y - 1, 0), Quaternion.identity);
                         Destroy(gameObject);
                         GameObject.Find("ScoringSystem").GetComponent <ScoringSystem>().increaseScore();
                     }
                 }
             }
             else if (swipeAction.direction == SwipeDirection.Right)
             {
                 direction = "right";
                 if (block != null)
                 {
                     if (block.checkType(direction))
                     {
                         Instantiate(blockHalf1, new Vector3(gameObject.transform.position.x - 1, gameObject.transform.position.y, 0), Quaternion.identity);
                         Instantiate(blockHalf2, new Vector3(gameObject.transform.position.x + 1, gameObject.transform.position.y, 0), Quaternion.identity);
                         Destroy(gameObject);
                         GameObject.Find("ScoringSystem").GetComponent <ScoringSystem>().increaseScore();
                     }
                 }
             }
             else if (swipeAction.direction == SwipeDirection.DownRight)
             {
                 direction = "downright";
                 if (block != null)
                 {
                     if (block.checkType(direction))
                     {
                         Instantiate(blockHalf1, new Vector3(gameObject.transform.position.x + 1, gameObject.transform.position.y + 1, 0), Quaternion.identity);
                         Instantiate(blockHalf2, new Vector3(gameObject.transform.position.x - 1, gameObject.transform.position.y - 1, 0), Quaternion.identity);
                         Destroy(gameObject);
                         GameObject.Find("ScoringSystem").GetComponent <ScoringSystem>().increaseScore();
                     }
                 }
             }
             else if (swipeAction.direction == SwipeDirection.Down)
             {
                 direction = "down";
                 if (block != null)
                 {
                     if (block.checkType(direction))
                     {
                         Instantiate(blockHalf1, new Vector3(gameObject.transform.position.x, gameObject.transform.position.y + 1, 0), Quaternion.identity);
                         Instantiate(blockHalf2, new Vector3(gameObject.transform.position.x, gameObject.transform.position.y - 1, 0), Quaternion.identity);
                         Destroy(gameObject);
                         GameObject.Find("ScoringSystem").GetComponent <ScoringSystem>().increaseScore();
                     }
                 }
             }
             else if (swipeAction.direction == SwipeDirection.DownLeft)
             {
                 direction = "downleft";
                 if (block != null)
                 {
                     if (block.checkType(direction))
                     {
                         Instantiate(blockHalf1, new Vector3(gameObject.transform.position.x - 1, gameObject.transform.position.y + 1, 0), Quaternion.identity);
                         Instantiate(blockHalf2, new Vector3(gameObject.transform.position.x + 1, gameObject.transform.position.y - 1, 0), Quaternion.identity);
                         Destroy(gameObject);
                         GameObject.Find("ScoringSystem").GetComponent <ScoringSystem>().increaseScore();
                     }
                 }
             }
             else if (swipeAction.direction == SwipeDirection.Left)
             {
                 direction = "left";
                 if (block != null)
                 {
                     if (block.checkType(direction))
                     {
                         Instantiate(blockHalf1, new Vector3(gameObject.transform.position.x - 1, gameObject.transform.position.y, 0), Quaternion.identity);
                         Instantiate(blockHalf2, new Vector3(gameObject.transform.position.x + 1, gameObject.transform.position.y, 0), Quaternion.identity);
                         Destroy(gameObject);
                         GameObject.Find("ScoringSystem").GetComponent <ScoringSystem>().increaseScore();
                     }
                 }
             }
             else if (swipeAction.direction == SwipeDirection.UpLeft)
             {
                 direction = "upleft";
                 if (block != null)
                 {
                     if (block.checkType(direction))
                     {
                         Instantiate(blockHalf1, new Vector3(gameObject.transform.position.x + 1, gameObject.transform.position.y + 1, 0), Quaternion.identity);
                         Instantiate(blockHalf2, new Vector3(gameObject.transform.position.x - 1, gameObject.transform.position.y - 1, 0), Quaternion.identity);
                         Destroy(gameObject);
                         GameObject.Find("ScoringSystem").GetComponent <ScoringSystem>().increaseScore();
                     }
                 }
             }
             else
             {
                 block.GetComponent <Block>().swiped = false;
             }
         }
         else // handle the case of the block being swiped outside the sweetspot or the phone being in an incorrect orientation
         {
             GameObject.Find("ScoringSystem").GetComponent <ScoringSystem>().resetCombo();
             Destroy(gameObject);
         }
     }
 }
Beispiel #19
0
 void HandleLongPress(SwipeAction swipeAction)
 {
     //Debug.LogFormat("HandleLongPress: {0}", swipeAction);
 }
    public IEnumerator StartTutorial(UnityEngine.InputSystem.Controls.KeyControl key = null, SwipeAction swipe = SwipeAction.Nil)
    {
        anim.enabled        = false;
        waitForTutorial     = true;
        AudioListener.pause = true;
        if (key != null && swipe != SwipeAction.Nil)
        {
            enableInput(key);
            yield return(new WaitUntil(() => (key.isPressed || latestSwipe == swipe)));
        }
        else
        {
            yield return(new WaitForSeconds(3f));
        }
        waitForTutorial     = false;
        anim.enabled        = true;
        AudioListener.pause = false;

        if (StopTutorial != null)
        {
            StopTutorial.Invoke();
        }
    }
 public void UpdateMovement(SwipeAction swipeAction)
 {
     Anim.SetTrigger("Run");
 }