예제 #1
0
파일: TouchInput.cs 프로젝트: theseim/VPET
        //!
        //! Update is called once per frame
        //!
        void Update()
        {
            if (!pause)
            {
                if (Input.touchCount == 1)
                {
                    //single touch gesture
                    if (Input.GetTouch(0).phase == TouchPhase.Began)
                    {
                        //finger down
                        inputAdapter.singlePointerStarted(Input.mousePosition);
                        singlePointerDrag = true;
                    }
                    else if (Input.GetTouch(0).phase == TouchPhase.Ended)
                    {
                        //finger up
                        inputAdapter.singlePointerEnded(Input.mousePosition);
                        singlePointerDrag = false;
                        pause             = true;
                    }
                    else if (singlePointerDrag)
                    {
                        //pointer down and moving
                        inputAdapter.singlePointerDrag(Input.mousePosition);
                    }
                }
                else if (Input.touchCount == 2)
                {
                    //2 pointer touch gesture
                    if (Input.GetTouch(1).phase == TouchPhase.Began)
                    {
                        //finger down
                        if (singlePointerDrag)
                        {
                            inputAdapter.singlePointerEnded(Input.mousePosition);
                            singlePointerDrag = false;
                        }
                        inputAdapter.twoPointerStarted(Input.mousePosition);
                        twoPointerDrag = true;
                    }
                    else if ((Input.GetTouch(0).phase == TouchPhase.Ended ||
                              Input.GetTouch(1).phase == TouchPhase.Ended))
                    {
                        //finger up
                        inputAdapter.twoPointerEnded(Input.mousePosition);
                        twoPointerDrag = false;
                        pause          = true;
                    }
                    else if (twoPointerDrag)
                    {
                        //pointer down and moving
                        Vector2 touchZeroPrevPos    = Input.GetTouch(0).position - Input.GetTouch(0).deltaPosition;
                        Vector2 touchOnePrevPos     = Input.GetTouch(1).position - Input.GetTouch(1).deltaPosition;
                        float   prevTouchDeltaMag   = (touchZeroPrevPos - touchOnePrevPos).magnitude;
                        float   touchDeltaMag       = (Input.GetTouch(0).position - Input.GetTouch(1).position).magnitude;
                        float   deltaMagnitudeScale = touchDeltaMag / prevTouchDeltaMag;

                        inputAdapter.pinchToZoom(deltaMagnitudeScale);

                        inputAdapter.twoPointerDrag(Input.mousePosition);
                    }
                }
                else if (Input.touchCount == 3)
                {
                    //3 pointer touch gesture
                    if (Input.GetTouch(2).phase == TouchPhase.Began)
                    {
                        //finger down
                        inputAdapter.threePointerStarted(Input.mousePosition);
                        threePointerDrag = true;
                    }
                    else if ((Input.GetTouch(0).phase == TouchPhase.Ended ||
                              Input.GetTouch(1).phase == TouchPhase.Ended ||
                              Input.GetTouch(2).phase == TouchPhase.Ended))
                    {
                        //finger up
                        inputAdapter.threePointerEnded(Input.mousePosition);
                        threePointerDrag = false;
                        pause            = true;
                    }
                    else if (threePointerDrag)
                    {
                        //pointer down and moving
                        inputAdapter.threePointerDrag(Input.mousePosition);
                    }
                }
            }
            else if (Input.touchCount == 0 && pause)
            {
                pause = false;
            }
        }
예제 #2
0
        //!
        //! Update is called once per frame
        //!
        void Update()
        {
            if (!pause)
            {
                if (Input.touchCount == 1)
                {
                    //single touch gesture
                    if (Input.GetTouch(0).phase == TouchPhase.Began)
                    {
                        //finger down
                        inputAdapter.singlePointerStarted(Input.mousePosition);
                        singlePointerDrag = true;
                    }
                    else if (Input.GetTouch(0).phase == TouchPhase.Ended)
                    {
                        //finger up
                        inputAdapter.singlePointerEnded(Input.mousePosition);
                        singlePointerDrag = false;
                        pause             = true;
                    }
                    else if (singlePointerDrag)
                    {
                        //pointer down and moving
                        inputAdapter.singlePointerDrag(Input.mousePosition);
                    }
                }
                else if (Input.touchCount == 2)
                {
                    //2 pointer touch gesture
                    if (Input.GetTouch(1).phase == TouchPhase.Began)
                    {
                        //finger down
                        if (singlePointerDrag)
                        {
                            inputAdapter.singlePointerEnded(Input.mousePosition);
                            singlePointerDrag = false;
                        }
                        inputAdapter.twoPointerStarted(Input.mousePosition);
                        twoPointerDrag = true;
                        m_initDistance = Vector2.Distance(Input.GetTouch(1).position, Input.GetTouch(0).position);
                        Vector2 initVector2D = Input.GetTouch(1).position - Input.GetTouch(0).position;
                        m_initVector = new Vector3(initVector2D.x, initVector2D.y, 0.0f);
                    }
                    else if ((Input.GetTouch(0).phase == TouchPhase.Ended ||
                              Input.GetTouch(1).phase == TouchPhase.Ended))
                    {
                        //finger up
                        inputAdapter.twoPointerEnded(Input.mousePosition);
                        twoPointerDrag = false;
                        pause          = true;
                    }
                    else if (twoPointerDrag)
                    {
                        //pinchToZoom
                        Vector2 touchDelta = Input.GetTouch(1).position - Input.GetTouch(0).position;
                        float   angle      = Vector3.SignedAngle(touchDelta, m_initVector, new Vector3(0, 0, 1));
                        float   distance   = Vector2.Distance(Input.GetTouch(1).position, Input.GetTouch(0).position) / m_initDistance;
                        inputAdapter.pinchToZoom(angle, distance);

                        inputAdapter.twoPointerDrag(Input.mousePosition);
                    }
                }
                else if (Input.touchCount == 3)
                {
                    //3 pointer touch gesture
                    if (Input.GetTouch(2).phase == TouchPhase.Began)
                    {
                        //finger down
                        inputAdapter.threePointerStarted(Input.mousePosition);
                        threePointerDrag = true;
                    }
                    else if ((Input.GetTouch(0).phase == TouchPhase.Ended ||
                              Input.GetTouch(1).phase == TouchPhase.Ended ||
                              Input.GetTouch(2).phase == TouchPhase.Ended))
                    {
                        //finger up
                        inputAdapter.threePointerEnded(Input.mousePosition);
                        threePointerDrag = false;
                        pause            = true;
                    }
                    else if (threePointerDrag)
                    {
                        //pointer down and moving
                        inputAdapter.threePointerDrag(Input.mousePosition);
                    }
                }
            }
            else if (Input.touchCount == 0 && pause)
            {
                pause = false;
            }
        }