Example #1
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;
                    }
                    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;
            }
        }
Example #2
0
 //!
 //! Update is called once per frame
 //!
 void Update()
 {
     if (Input.touchCount == 0) // no touch input needed for devices with touch and mouse
     {
         //single mouse gesture
         if (Input.GetMouseButtonDown(0))
         {
             //left mouse Button down
             if (Input.GetKey(KeyCode.Alpha3))
             {
                 inputAdapter.threePointerStarted(Input.mousePosition);
             }
             else if (Input.GetKey(KeyCode.Alpha2))
             {
                 inputAdapter.twoPointerStarted(Input.mousePosition);
             }
             else
             {
                 inputAdapter.singlePointerStarted(Input.mousePosition);
             }
             startMousePosition = Input.mousePosition;
             drag = true;
         }
         else if (Input.GetMouseButtonUp(0))
         {
             //left mouse Button up
             if (Input.GetKey(KeyCode.Alpha3))
             {
                 inputAdapter.threePointerEnded(Input.mousePosition);
             }
             else if (Input.GetKey(KeyCode.Alpha2))
             {
                 inputAdapter.twoPointerEnded(Input.mousePosition);
             }
             else
             {
                 inputAdapter.singlePointerEnded(Input.mousePosition);
             }
             drag = false;
         }
         else if (drag)
         {
             //left mouse Button down and mouse moving
             if (Input.GetKey(KeyCode.Alpha3))
             {
                 inputAdapter.threePointerDrag(Input.mousePosition);
             }
             else if (Input.GetKey(KeyCode.Alpha2))
             {
                 inputAdapter.twoPointerDrag(Input.mousePosition);
             }
             else if (Input.GetKey(KeyCode.Alpha1))
             {
                 // set rotation
                 Vector3    _mouseDelta = Input.mousePosition - startMousePosition;
                 Quaternion _rotation   = Quaternion.Euler(-_mouseDelta.y * Time.deltaTime, _mouseDelta.x * Time.deltaTime, 0);
                 moveCamera.transform.localRotation *= _rotation;
             }
             else
             {
                 inputAdapter.singlePointerDrag(Input.mousePosition);
             }
         }
     }
 }
Example #3
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;
            }
        }