public void OnDrag(NoteAreaDragEvent dragEvent) { if (dragEvent.GeneralDragEvent.InputButton != PointerEventData.InputButton.Middle && Touch.activeTouches.Count < 2) { return; } if (Touch.activeTouches.Count == 2) { if (twoFingerGestureStartDistance < 0) { twoFingerGestureStartDistance = Vector2.Distance(Touch.activeTouches[0].screenPosition, Touch.activeTouches[1].screenPosition); } else { // The touches must all move in the same direction. Thus, their distance to each other must be (near) constant. float distance = Vector2.Distance(Touch.activeTouches[0].screenPosition, Touch.activeTouches[1].screenPosition); if (Math.Abs(distance - twoFingerGestureStartDistance) > TouchGestureMoveInSameDirectionThreshold) { CancelDrag(); return; } } } int newViewportX = viewportXBeginDrag - dragEvent.MillisDistance; int newViewportY = viewportYBeginDrag - dragEvent.MidiNoteDistance; noteArea.SetViewport(newViewportX, newViewportY, noteArea.ViewportWidth, noteArea.ViewportHeight); }