/// <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; } } } }
/// <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 }
/// <inheritdoc /> protected override Vector2 getPointPreviousScreenPosition(int index) { if (!clusters.HasClusters) { return(ClusterUtils.GetPrevious2DCenterPosition(activeTouches)); } return(clusters.GetPreviousCenterPosition(index)); }
/// <summary> /// Calculates previous center position of one of the clusters. /// </summary> /// <param name="id"> Cluster id. Either <see cref="CLUSTER1"/> or <see cref="CLUSTER2"/>. </param> /// <returns> Cluster's centroid previous position or <see cref="TouchManager.INVALID_POSITION"/> if cluster contains no pointers. </returns> public Vector2 GetPreviousCenterPosition(int id) { if (!HasClusters) { return(TouchManager.INVALID_POSITION); } Vector2 result; switch (id) { case CLUSTER1: result = ClusterUtils.GetPrevious2DCenterPosition(cluster1); break; case CLUSTER2: result = ClusterUtils.GetPrevious2DCenterPosition(cluster2); break; default: return(TouchManager.INVALID_POSITION); } return(result); }
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); }
/// <inheritdoc /> protected override Vector2 getPointPreviousScreenPosition() { return(ClusterUtils.GetPrevious2DCenterPosition(activeTouches)); }