コード例 #1
0
ファイル: InputTouch.cs プロジェクト: bell11223344/Calendar
    void GetDirection()
    {
        float  directionX = touchEndPos.x - touchStartPos.x;
        float  directionY = touchEndPos.y - touchStartPos.y;
        string Direction  = "";

        if (Mathf.Abs(directionY) < Mathf.Abs(directionX))
        {
            if (30 < directionX)
            {
                //右向きにフリック
                Direction = "right";
            }
            else if (-30 > directionX)
            {
                //左向きにフリック
                Direction = "left";
            }
        }
        else if (Mathf.Abs(directionX) < Mathf.Abs(directionY))
        {
            if (30 < directionY)
            {
                //上向きにフリック
                Direction = "up";
            }
            else if (-30 > directionY)
            {
                //下向きのフリック
                Direction = "down";
            }
            else
            {
                //タッチを検出
                Direction = "touch";
            }
        }

        switch (Direction)
        {
        case "up":
            //上フリックされた時の処理
            Debug.Log("上フリック");
            break;

        case "down":
            //下フリックされた時の処理
            Debug.Log("下フリック");
            break;

        case "right":
            //右フリックされた時の処理
            Debug.Log("右フリック");
            calendar.current = calendar.current.AddMonths(-1);
            calendar.SetCalendar();
            break;

        case "left":
            //左フリックされた時の処理
            Debug.Log("左フリック");
            calendar.current = calendar.current.AddMonths(1);
            calendar.SetCalendar();
            break;

        case "touch":
            //タッチされた時の処理
            Debug.Log("タッチ");
            break;
        }
    }