コード例 #1
0
ファイル: Joystick4dController.cs プロジェクト: matibat/snake
    void RefreshDirection(Touch touch)
    {
        currentPosition = GetTouchPosition(touch);
        Vector3 directionVector = GetDirectionVector();
        bool    hasMoved        = directionVector.magnitude > sensivility;

        if (!hasMoved)
        {
            direction = j4dDirection.center;
        }
        else
        {
            float        angle        = Vector3.SignedAngle(startPointVector, directionVector, Vector3.back);
            j4dDirection newDirection = direction;
            if (angle >= 0 && angle < 90)
            {
                newDirection = j4dDirection.up;
            }
            else if (angle >= 90 && angle < 180)
            {
                newDirection = j4dDirection.right;
            }
            else if (angle >= -180 && angle < -90)
            {
                newDirection = j4dDirection.down;
            }
            else if (angle >= -90 && angle < 0)
            {
                newDirection = j4dDirection.left;
            }
            if (newDirection != direction)
            {
                direction = newDirection;
                onDirectionChanged.Invoke();
            }
        }
    }
コード例 #2
0
ファイル: JoystickNavigation.cs プロジェクト: matibat/snake
 public void HandleJoystickAction(j4dDirection direction)
 {
     Debug.Log("Joystick moved: " + direction);
     if (direction == j4dDirection.up)
     {
         Vector3 nextPosition = new Vector3(0, 1, 0);
         boardManager.AttemptToMove(nextPosition);
     }
     if (direction == j4dDirection.right)
     {
         Vector3 nextPosition = new Vector3(1, 0, 0);
         boardManager.AttemptToMove(nextPosition);
     }
     if (direction == j4dDirection.down)
     {
         Vector3 nextPosition = new Vector3(0, -1, 0);
         boardManager.AttemptToMove(nextPosition);
     }
     if (direction == j4dDirection.left)
     {
         Vector3 nextPosition = new Vector3(-1, 0, 0);
         boardManager.AttemptToMove(nextPosition);
     }
 }
コード例 #3
0
ファイル: JoystickNavigation.cs プロジェクト: matibat/snake
    public void OnEnd()
    {
        j4dDirection direction = controller.direction;

        HandleJoystickAction(direction);
    }
コード例 #4
0
ファイル: Joystick4dController.cs プロジェクト: matibat/snake
 void CleanState()
 {
     pivotPoint      = null;
     currentPosition = null;
     direction       = j4dDirection.center;
 }