internal void recognizeTouches(List <TSTouch> touches) { for (var i = touches.Count - 1; i >= 0; i--) { TSTouch touch = touches[i]; switch (touch.phase) { case TouchPhase.Began: { touchesBegan(touches); break; } case TouchPhase.Moved: { touchesMoved(touches); break; } case TouchPhase.Ended: case TouchPhase.Canceled: { touchesEnded(touches); break; } } } }
internal override bool canTrigger(List <TSTouch> touches) { if (touches.Count == touchCounts) { bool result = true; for (int i = 0; i < touchCounts; i++) { TSTouch touch = touches[i]; if (touch.phase != TouchPhase.Ended && touch.deltaPosition.magnitude > minMoveDistance) { } else { result = false; } } if (result) { result = isIdentical(touches); } if (result && gestureCanTrigger != null) { return(gestureCanTrigger()); } else { return(result); } } return(false); }
void Awake() { touchesCache = new TSTouch[maxTouches]; for (int i = 0; i < maxTouches; i++) { touchesCache[i] = new TSTouch(i); } }
private void gestureRecognized() { TSTouch touch0 = tracingTouches[0]; TSTouch touch1 = tracingTouches[1]; float currentDistance = vector2Distance(touch0, touch1); deltaDistance = currentDistance - distance; distance = currentDistance; emitRecognizedEvent(); }
internal override bool canTrigger(List <TSTouch> touches) { if (touches.Count == 1) { TSTouch touch = touches[0]; if (touch.phase == TouchPhase.Ended && touch.deltaPosition.magnitude < maxMoveDistance) { return(true); } } return(false); }
internal override void touchesEnded(List <TSTouch> touches) { if (touches.Count == 1) { TSTouch touch = touches[0]; tracingTouches.Add(touch); state = RecognizerState.Recognized; emitRecognizedEvent(); } state = RecognizerState.Ended; end(); reset(); }
private void gestureEnd() { if (state == RecognizerState.Recognized || state == RecognizerState.Began) { state = RecognizerState.Ended; TSTouch touch0 = tracingTouches[0]; TSTouch touch1 = tracingTouches[1]; float currentDistance = vector2Distance(touch0, touch1); deltaDistance = currentDistance - distance; distance = currentDistance; emitEndEvent(); end(); reset(); } }
internal override void touchesMoved(List <TSTouch> touches) { if (touches.Count == 2) { // if (!isOpposite(touches)) // { // gestureEnd(); // } if (state == RecognizerState.Possible) { state = RecognizerState.Began; for (int i = 0; i < 2; i++) { TSTouch touch = touches[i]; tracingTouches.Add(touch); } TSTouch touch0 = tracingTouches[0]; TSTouch touch1 = tracingTouches[1]; startDistance = vector2Distance(touch0, touch1); distance = startDistance; deltaDistance = 0; emitBeginEvent(); } else if (state == RecognizerState.Began) { state = RecognizerState.Recognized; gestureRecognized(); } else if (state == RecognizerState.Recognized) { gestureRecognized(); } } }
internal override bool canTrigger(List <TSTouch> touches) { if (touches.Count == 2) { bool result = true; for (int i = 0; i < 2; i++) { TSTouch touch = touches[i]; if (touch.phase != TouchPhase.Ended && touch.deltaPosition.magnitude > minMoveDistance) { } else { result = false; } } if (result) { return(isOpposite(touches)); } } return(false); }
internal override void touchesMoved(List <TSTouch> touches) { if (touches.Count == touchCounts) { // if (!isIdentical(touches)) // { // gestureEnd(); // } if (state == RecognizerState.Possible) { state = RecognizerState.Began; for (int i = 0; i < touchCounts; i++) { TSTouch touch = touches[i]; tracingTouches.Add(touch); } startPosition = midStartPosition(tracingTouches); position = midPosition(tracingTouches); deltaPosition = midDeltaPosition(tracingTouches); emitBeginEvent(); } else if (state == RecognizerState.Began) { state = RecognizerState.Recognized; gestureRecognized(); } else if (state == RecognizerState.Recognized) { gestureRecognized(); } } }
private float vector2Distance(TSTouch t1, TSTouch t2) { return(Vector2.Distance(t1.position, t2.position)); }