Example #1
0
        /// <inheritdoc />
        protected void LateUpdate()
        {
            if (!isActive)
            {
                return;
            }

            deltaSequence.Add(ScreenPosition - PreviousScreenPosition);
        }
Example #2
0
        /// <summary>
        /// Called if touches are removed.
        /// </summary>
        /// <param name="touches">The touches.</param>
        protected virtual void touchesEnded(IList <ITouch> touches)
        {
            if (combineTouches)
            {
                foreach (var touch in touches)
                {
                    touchSequence.Add(touch);
                }

                if (activeTouches.Count == 0)
                {
                    // Checking which points were removed in clusterExistenceTime seconds to set their centroid as cached screen position
                    var cluster = touchSequence.FindElementsLaterThan(Time.time - combineTouchesInterval, shouldCacheTouchPosition);
                    cachedScreenPosition         = ClusterUtils.Get2DCenterPosition(cluster);
                    cachedPreviousScreenPosition = ClusterUtils.GetPrevious2DCenterPosition(cluster);
                }
            }
            else
            {
                if (activeTouches.Count == 0)
                {
                    var lastPoint = touches[touches.Count - 1];
                    if (shouldCacheTouchPosition(lastPoint))
                    {
                        cachedScreenPosition         = lastPoint.Position;
                        cachedPreviousScreenPosition = lastPoint.PreviousPosition;
                    }
                    else
                    {
                        cachedScreenPosition         = TouchManager.INVALID_POSITION;
                        cachedPreviousScreenPosition = TouchManager.INVALID_POSITION;
                    }
                }
            }
        }
Example #3
0
        /// <inheritdoc />
        protected override void pointersReleased(IList <Pointer> pointers)
        {
#if UNITY_5_6_OR_NEWER
            gestureSampler.Begin();
#endif

            base.pointersReleased(pointers);

            if (combinePointers)
            {
                var count = pointers.Count;
                for (var i = 0; i < count; i++)
                {
                    pointerSequence.Add(pointers[i]);
                }

                if (NumPointers == 0)
                {
                    // Checking which points were removed in clusterExistenceTime seconds to set their centroid as cached screen position
                    var cluster = pointerSequence.FindElementsLaterThan(Time.unscaledTime - combinePointersInterval, shouldCachePointerPosition);
                    cachedScreenPosition         = ClusterUtils.Get2DCenterPosition(cluster);
                    cachedPreviousScreenPosition = ClusterUtils.GetPrevious2DCenterPosition(cluster);
                }
            }
            else
            {
                if (NumPointers == 0)
                {
                    if (!isActive)
                    {
                        setState(GestureState.Failed);
#if UNITY_5_6_OR_NEWER
                        gestureSampler.End();
#endif
                        return;
                    }

                    // pointers outside of gesture target are ignored in shouldCachePointerPosition()
                    // if all pointers are outside ScreenPosition will be invalid
                    if (TouchManager.IsInvalidPosition(ScreenPosition))
                    {
                        setState(GestureState.Failed);
                    }
                    else
                    {
                        tapsDone++;
                        isActive = false;
                        if (tapsDone >= numberOfTapsRequired)
                        {
                            setState(GestureState.Recognized);
                        }
                    }
                }
            }

#if UNITY_5_6_OR_NEWER
            gestureSampler.End();
#endif
        }
Example #4
0
        internal void INTERNAL_TouchEnded(TouchPoint touch)
        {
            var total = numTouches - 1;

            touchesNumState = TouchesNumState.InRange;

            if (minTouches <= 0)
            {
                // have no touches
                if (total == 0)
                {
                    touchesNumState = TouchesNumState.PassedMinThreshold;
                }
            }
            else
            {
                if (numTouches >= minTouches)
                {
                    // had >= minTouches, got < minTouches
                    if (total < minTouches)
                    {
                        touchesNumState = TouchesNumState.PassedMinThreshold;
                    }
                }
                // last event we already were under minTouches
                else
                {
                    touchesNumState = TouchesNumState.TooFew;
                }
            }

            if (maxTouches > 0)
            {
                if (numTouches > maxTouches)
                {
                    if (total <= maxTouches)
                    {
                        // this event we crossed both minTouches and maxTouches
                        if (touchesNumState == TouchesNumState.PassedMinThreshold)
                        {
                            touchesNumState = TouchesNumState.PassedMinMaxThreshold;
                        }
                        // this event we crossed maxTouches
                        else
                        {
                            touchesNumState = TouchesNumState.PassedMaxThreshold;
                        }
                    }
                    // last event we already were over maxTouches
                    else
                    {
                        touchesNumState = TouchesNumState.TooMany;
                    }
                }
            }

            activeTouches.Remove(touch);
            numTouches = total;

            if (combineTouches)
            {
                touchSequence.Add(touch);

                if (NumTouches == 0)
                {
                    // Checking which points were removed in clusterExistenceTime seconds to set their centroid as cached screen position
                    var cluster = touchSequence.FindElementsLaterThan(Time.time - combineTouchesInterval,
                                                                      shouldCacheTouchPosition);
                    cachedScreenPosition         = ClusterUtils.Get2DCenterPosition(cluster);
                    cachedPreviousScreenPosition = ClusterUtils.GetPrevious2DCenterPosition(cluster);
                }
            }
            else
            {
                if (NumTouches == 0)
                {
                    if (shouldCacheTouchPosition(touch))
                    {
                        cachedScreenPosition         = touch.Position;
                        cachedPreviousScreenPosition = touch.PreviousPosition;
                    }
                    else
                    {
                        cachedScreenPosition         = TouchManager.INVALID_POSITION;
                        cachedPreviousScreenPosition = TouchManager.INVALID_POSITION;
                    }
                }
            }

            touchEnded(touch);
        }