Esempio n. 1
0
            void Update()
            {
#if MOBILE_INPUT
                // Copy Touches to Local Struct Array (We can't create instances of Unity 'Touch')
                m_TouchCount = Input.touchCount;
                var        touches = Input.touches;
                Touch      touch;
                TouchPoint touchPoint;

                for (int t = 0; t < touches.Length; ++t)
                {
                    touch      = touches[t];
                    touchPoint = m_ActiveTouches[t];
                    touchPoint.deltaPosition = touch.deltaPosition;
                    touchPoint.position      = touch.position;
                    touchPoint.phase         = touch.phase;
                    touchPoint.fingerId      = touch.fingerId;
                    touchPoint.tapCount      = touch.tapCount;
                    touchPoint.deltaTime     = touch.deltaTime;

                    m_ActiveTouches[t] = touchPoint;
                }

                //Vector2 debugPoint = Vector2.zero;
                if (m_TouchCount == 1)
                {
                    m_Horizontal = m_ActiveTouches[0].deltaPosition.x;
                    m_Vertical   = m_ActiveTouches[0].deltaPosition.y;
                    //debugPoint = m_ActiveTouches[ 0 ].position;
                }
                else
                {
                    m_Horizontal = 0f;
                    m_Vertical   = 0f;
                }

                //DebugToScreen.Log( "InputManager: m_TouchCount: " + m_TouchCount + " m_Horizontal: " + m_Horizontal + " m_Vertical: " + m_Vertical
                //    + " debugPoint: " + debugPoint );
#else
                Vector2    mousePosition  = Input.mousePosition;
                TouchPoint touchPoint     = new TouchPoint();
                int        lastTouchCount = m_TouchCount;
                float      time           = Time.time;

                if (lastTouchCount == 0)
                {
                    //--------------
                    // 0 Touches
                    //--------------
                    if (Input.GetMouseButtonDown(0))
                    {
                        m_TouchCount = 1;
                        //---------------
                        // Create Touch 1
                        //---------------
                        if (m_ActiveTouches[0].tapCount > 0 && (time - m_ActiveTouchTimes[0]) < tapMultiThresholdSec)
                        {
                            // Multi-Tap Possible
                            m_ActiveTouches[0].deltaPosition = mousePosition - m_ActiveTouches[0].position;
                            m_ActiveTouches[0].position      = mousePosition;
                            m_ActiveTouches[0].phase         = TouchPhase.Began;
                        }
                        else
                        {
                            touchPoint.Set(TouchPhase.Began, 0f, 0, 0, Input.mousePosition, Vector2.zero);
                            m_ActiveTouches[0] = touchPoint;
                        }
                        m_ActiveTouchTimes[0] = time;

                        // Fire Press Event
                        //Press( m_ActiveTouches[ 0 ], EventArgs.Empty );
                    }
                }
                else if (lastTouchCount == 1)
                {
                    //--------------
                    // 1 Touch
                    //--------------
                    if (Input.GetKey(KeyCode.LeftAlt) && Input.GetMouseButtonDown(0))
                    {
                        m_TouchCount = 2;
                        //---------------
                        // Create Touch 2
                        //---------------
                        if (m_ActiveTouches[1].tapCount > 0 && (time - m_ActiveTouchTimes[1]) < tapMultiThresholdSec)
                        {
                            // Multi-Tap Possible
                            m_ActiveTouches[1].deltaPosition = mousePosition - m_ActiveTouches[1].position;
                            m_ActiveTouches[1].position      = mousePosition;
                            m_ActiveTouches[1].phase         = TouchPhase.Began;
                        }
                        else
                        {
                            touchPoint.Set(TouchPhase.Began, 0f, 0, 1, Input.mousePosition, Vector2.zero);
                            m_ActiveTouches[1] = touchPoint;
                        }
                        m_ActiveTouchTimes[1] = time;

                        // Fire Press Event
                        //Press( m_ActiveTouches[ 0 ], EventArgs.Empty );
                    }
                    else if (!Input.GetMouseButton(0) && !Input.GetKey(KeyCode.LeftAlt))
                    {
                        m_TouchCount = 0;
                        //---------------
                        // Release Touch 1
                        //---------------
                        if ((time - m_ActiveTouchTimes[0]) < tapThresholdSec)
                        {
                            // Tap
                            m_ActiveTouches[0].tapCount     += 1;
                            m_ActiveTouches[0].deltaPosition = mousePosition - m_ActiveTouches[0].position;
                            m_ActiveTouches[0].position      = mousePosition;
                            m_ActiveTouches[0].phase         = TouchPhase.Ended;
                        }
                        m_ActiveTouchTimes[0] = time;

                        // Fire Release Event
                        //Release( m_ActiveTouches[ 0 ], EventArgs.Empty );
                    }
                    else
                    {
                        // Update Touch 1
                        m_ActiveTouches[0].deltaPosition = mousePosition - m_ActiveTouches[0].position;
                        m_ActiveTouches[0].position      = mousePosition;
                        m_ActiveTouches[0].phase         = TouchPhase.Moved;
                    }
                }
                else if (lastTouchCount == 2)
                {
                    //--------------
                    // 2 Touches
                    //--------------
                    if (Input.GetKey(KeyCode.LeftAlt) && !Input.GetMouseButton(0))
                    {
                        m_TouchCount = 1;
                        //---------------
                        // Release Touch 2
                        //---------------
                        if ((time - m_ActiveTouchTimes[1]) < tapThresholdSec)
                        {
                            // Tap
                            m_ActiveTouches[1].tapCount     += 1;
                            m_ActiveTouches[1].deltaPosition = mousePosition - m_ActiveTouches[0].position;
                            m_ActiveTouches[1].position      = mousePosition;
                            m_ActiveTouches[1].phase         = TouchPhase.Ended;
                        }
                        m_ActiveTouchTimes[1] = time;

                        // Fire Release Event
                        //Release( m_ActiveTouches[ 1 ], EventArgs.Empty );
                    }
                    else if (!Input.GetKey(KeyCode.LeftAlt) && !Input.GetMouseButton(0))
                    {
                        m_TouchCount = 0;
                        // No Touches
                    }
                    else
                    {
                        // Update Touch 2
                        m_ActiveTouches[1].deltaPosition = mousePosition - m_ActiveTouches[0].position;
                        m_ActiveTouches[1].position      = mousePosition;
                        m_ActiveTouches[1].phase         = TouchPhase.Moved;
                    }
                }
                else
                {
                    // Invalid State
                    m_TouchCount = 0;
                }

                // Update Axis
                if (m_TouchCount == 1)
                {
                    m_Horizontal = Input.GetAxis("Mouse X");
                    m_Vertical   = Input.GetAxis("Mouse Y");
                }
                else
                {
                    m_Horizontal = 0f;
                    m_Vertical   = 0f;
                }

                // Update All Tap DeltaTime
                for (int t = 0; t < m_TouchCount; ++t)
                {
                    m_ActiveTouches[t].deltaTime += Time.deltaTime;
                }

                // Whew.... Definitely not Object Oriented but hey, works for this gig
#endif



                UpdateGestures();

                //----------------
                // DELETE
                //if(m_TouchCount == 2) {
                //    DebugToScreen.Log( "InputManager: Touch Count is 2" );
                //}
                //----------------

                //Debug.Log( "InputManager: Update() m_TouchCount: " + m_TouchCount + " Horizontal: " + m_Horizontal + " Vertical: " + m_Vertical
                //    + " Touch[0] TapCount: " + m_ActiveTouches[ 0 ].tapCount + " Touch[1] TapCount: " + m_ActiveTouches[ 1 ].tapCount );
            }