Exemplo n.º 1
0
        private void Update()
        {
            // if there are no touch to be processed, just ignore the following instructions
            if (Input.touchCount <= 0)
            {
                return;
            }

            // loop through each touch and process it according to its phase
            foreach (Touch touch in Input.touches)
            {
                if (touch.phase == TouchPhase.Began)
                {
                    // If this touch is on UI elements or PhysicsRaycaster targets, mark as invalid
                    if (EventSystem.current.IsPointerOverGameObject(touch.fingerId))
                    {
                        SetTouchState(touch.fingerId, TouchState.Invalid);
                    }
                    else // if not, we can mark it as a valid touch
                    {
                        SetTouchState(touch.fingerId, TouchState.Valid);
                    }
                }
                else if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled)
                {
                    if (IsTouchInDictionaryInvalid(touch.fingerId))
                    {
                        continue;
                    }

                    bool isTouchMoved = (touchStateDictionary[touch.fingerId] == TouchState.Moved);

                    // this touch leaves screen, so set it to invalid
                    // need to do this after assigning isTouchMoved, otherwise it'll be corrupted
                    touchStateDictionary[touch.fingerId] = TouchState.Invalid;

                    if (OnTouchEnded != null)
                    {
                        EndedTouchEventArgs eventArgs = new EndedTouchEventArgs(isTouchMoved, touch.position);
                        OnTouchEnded.Invoke(this, eventArgs);
                    }
                }
                else if (touch.phase == TouchPhase.Moved)
                {
                    // if this touch is invalid, don't reset it to moved
                    if (IsTouchInDictionaryInvalid(touch.fingerId))
                    {
                        continue;
                    }

                    touchStateDictionary[touch.fingerId] = TouchState.Moved;

                    if (OnTouchMoving != null)
                    {
                        MotionEventArgs eventArgs = new MotionEventArgs(touch.deltaPosition);
                        OnTouchMoving.Invoke(this, eventArgs);
                    }
                }
            }
        }
        private void OnTouchEnded(Object sender, EndedTouchEventArgs eventArgs)
        {
            if (eventArgs.isTouchMoved)
            {
                return;
            }

            // fire a ray and restart scanner
            m_scanningEffect.ResetOriginByCameraRay(eventArgs.position);
        }