private void DetectPinchAndPanGestures(TouchActionType touchActionType) { TouchManipulationInfo[] infos = new TouchManipulationInfo[_touchDictionary.Count]; _touchDictionary.Values.CopyTo(infos, 0); if (infos.Length == 1) { SKPoint previousPoint = infos[0].PreviousPoint; SKPoint newPoint = infos[0].NewPoint; OnPan?.Invoke(this, new PanEventArgs(previousPoint, newPoint, touchActionType)); } else if (infos.Length >= 2) { int pivotIndex = infos[0].NewPoint == infos[0].PreviousPoint ? 0 : 1; SKPoint pivotPoint = infos[pivotIndex].NewPoint; SKPoint newPoint = infos[1 - pivotIndex].NewPoint; SKPoint previousPoint = infos[1 - pivotIndex].PreviousPoint; OnPinch?.Invoke(this, new PinchEventArgs(previousPoint, newPoint, pivotPoint, touchActionType)); if (TwoFingersPanEnabled) { SKPoint delta = newPoint - previousPoint; SKPoint halfOfDelta = new SKPoint(0.5f * delta.X, 0.5f * delta.Y); OnPan?.Invoke(this, new PanEventArgs(new SKPoint(), halfOfDelta, touchActionType)); } } }
protected void Pinch(OnPinch e) { GameCamera gCam = GetGameCamera(); if (gCam.TransitionRunning) { return; } if (GameManager.Instance.LoadedScene == SceneString.MapView) { MapViewDistance += e.value / 100f; if (FtueManager.instance.active) { if (_mapViewDistance <= 3f && !_endCalled) { _endCalled = true; Events.Instance.Raise(new OnPinchEnd()); } } else if (_mapViewDistance <= MinMapDistance && !_endCalled) { _endCalled = true; Events.Instance.Raise(new OnPinchEnd()); } } else { if (e.value > 0) { DistanceToplayer += e.value / 1000f; if (_distanceToplayer >= MaxZoomDistance && !_endCalled) { _endCalled = true; Events.Instance.Raise(new OnPinchEnd()); } } else if (e.value < 0) { if (_distanceToplayer >= MinZoomDistance && !_endCalled) { DistanceToplayer += e.value / 1000f; } } } }
private void DetectPinchAndPanGestures(TouchActionType touchActionType) { TouchManipulationInfo[] infos = new TouchManipulationInfo[_touchDictionary.Count]; _touchDictionary.Values.CopyTo(infos, 0); if (infos.Length == 1) { SKPoint previousPoint = infos[0].PreviousPoint; SKPoint newPoint = infos[0].NewPoint; OnPan?.Invoke(this, new PanEventArgs(previousPoint, newPoint, touchActionType)); } else if (infos.Length >= 2) { int pivotIndex = infos[0].NewPoint == infos[0].PreviousPoint ? 0 : 1; SKPoint pivotPoint = infos[pivotIndex].NewPoint; SKPoint newPoint = infos[1 - pivotIndex].NewPoint; SKPoint previousPoint = infos[1 - pivotIndex].PreviousPoint; OnPinch?.Invoke(this, new PinchEventArgs(previousPoint, newPoint, pivotPoint, touchActionType)); } }
private void ProcessInput(List <Touch> touches, InputState state) { switch (state) { case InputState.None: break; case InputState.Press: if (touches[0].phase == TouchPhase.Began) { OnPressStart?.Invoke(touches[0].position); } break; case InputState.Sliding: Vector3 prevPos = _prevTouches[0].position; Vector3 currentPos = touches[0].position; OnSlide?.Invoke(prevPos, currentPos); break; case InputState.Up: OnTouchUp?.Invoke(touches[0].position); break; case InputState.Pinch: if (_prevState != InputState.Pinch) { return; } float prevLength = (_prevTouches[0].position - _prevTouches[1].position).magnitude; float currentLength = (touches[0].position - touches[1].position).magnitude; OnPinch?.Invoke(Mathf.Abs(prevLength - currentLength)); break; default: break; } }
private void onPointerButtonInputPressed(PointerButtonInputEventArgs obj) { _pinchDuration += Time.deltaTime; fetchCurrentPointerInput(); OnPinch?.Invoke(new PinchInputEventArgs(PinchState.Ongoing, calculateAxis(), calculateDelta(), _currentPointerInput, _pinchDuration)); }
private void UpdateTouches() { if (input == null || input.TouchCount() == 0) { return; } if (input.TouchCount() == 1) { TouchInfo touchInfo = input.GetTouch(0); if (currentTouch.GestureType == GestureType.None) { actionStartTime = Time.realtimeSinceStartup; } touchInfo.StartTime = actionStartTime; if (touchInfo.Phase == TouchPhase.Began) { Touch touch = new Touch { TouchInfo = touchInfo, GestureType = GestureType.None, SwipeDirection = SwipeDirection.None, SwipeLength = 0, SwipeVector = Vector2.zero }; currentTouch = touch; OnTouchStart?.Invoke(touch); } if (touchInfo.Phase == TouchPhase.Moved) { OnTouch?.Invoke(new Touch { TouchInfo = touchInfo, GestureType = GestureType.None, }); if (touchInfo.PositionDelta.magnitude >= settings.GetSwipeLengthInPixels()) { Touch touch = new Touch { TouchInfo = touchInfo, GestureType = GestureType.Swipe, SwipeDirection = GetSwipeDirection(touchInfo.Position - touchInfo.PositionDelta, touchInfo.Position), SwipeLength = touchInfo.PositionDelta.magnitude, SwipeVector = touchInfo.PositionDelta }; switch (currentTouch.GestureType) { case GestureType.None: OnSwipeStart?.Invoke(touch); break; case GestureType.Swipe: OnSwipe?.Invoke(touch); break; } currentTouch = touch; return; } } if (touchInfo.Phase == TouchPhase.Stationary) { OnTouch?.Invoke(new Touch { TouchInfo = touchInfo, GestureType = GestureType.None, }); touchInfo.ActionTime = Time.realtimeSinceStartup - touchInfo.StartTime; currentTouch = new Touch { TouchInfo = touchInfo, GestureType = GestureType.Tap, SwipeDirection = SwipeDirection.None, SwipeLength = 0, SwipeVector = Vector2.zero }; } if (touchInfo.Phase == TouchPhase.Ended) { OnTouchEnd?.Invoke(new Touch { TouchInfo = touchInfo, GestureType = GestureType.None, }); switch (currentTouch.GestureType) { case GestureType.Swipe: OnSwipeEnd?.Invoke(currentTouch); break; case GestureType.Tap when currentTouch.TouchInfo.ActionTime <= settings.TapTime: OnTap?.Invoke(currentTouch); break; } } } if (input.TouchCount() == 2) { TouchInfo touch0 = input.GetTouch(0); TouchInfo touch1 = input.GetTouch(1); if (currentTouch.GestureType == GestureType.None) { actionStartTime = Time.realtimeSinceStartup; } touch0.StartTime = actionStartTime; if (touch0.Phase == TouchPhase.Began || touch1.Phase == TouchPhase.Began) { Pinch pinch = new Pinch { TouchInfos = new [] { touch0, touch1 }, GestureType = GestureType.None, PinchVector = touch0.Position - touch1.Position }; currentPinch = pinch; OnPinchStart?.Invoke(currentPinch); } if (touch0.Phase != TouchPhase.Stationary || touch0.Phase == TouchPhase.Moved || touch1.Phase != TouchPhase.Stationary || touch1.Phase == TouchPhase.Moved) { Pinch pinch = new Pinch { TouchInfos = new [] { touch0, touch1 }, GestureType = GestureType.Pinch, PinchVector = touch0.Position - touch1.Position }; currentPinch = pinch; OnPinch?.Invoke(currentPinch); } if (touch0.Phase == TouchPhase.Ended || touch1.Phase == TouchPhase.Ended) { Pinch pinch = new Pinch { TouchInfos = new [] { touch0, touch1 }, GestureType = GestureType.Pinch, PinchVector = touch0.Position - touch1.Position }; currentPinch = pinch; OnPinchEnd?.Invoke(currentPinch); } } }
public override void Update() { if (Input.touchCount == 2) { theTouchs[0] = Input.GetTouch(0); theTouchs[1] = Input.GetTouch(1); if (theTouchs[0].phase == TouchPhase.Began) { pinchHasFinished = false; // get the touch began and store the touch location pinchData[0].firstTouch = theTouchs[0].position; } if (theTouchs[1].phase == TouchPhase.Began) { pinchData[1].firstTouch = theTouchs[1].position; } if (theTouchs[0].phase == TouchPhase.Moved || theTouchs[1].phase == TouchPhase.Moved) { Vector2 pos = theTouchs[0].position; pinchData[0].lastTouch = pos; pinchData[1].lastTouch = theTouchs[1].position; float distance = Vector3.Distance(pinchData[0].firstTouch, pinchData[0].lastTouch); float distance2 = Vector3.Distance(pinchData[1].firstTouch, pinchData[1].lastTouch); if (distance > minimumPinchDistance && distance2 > minimumPinchDistance) { // then invoke the Onswipe event. OnPinch?.Invoke(this, new pinchMoveArgs(pinchData)); } } else if (theTouchs[0].phase == TouchPhase.Stationary && theTouchs[1].phase == TouchPhase.Stationary) { theTouchs[0].phase = TouchPhase.Ended; theTouchs[1].phase = TouchPhase.Ended; } // zero data else if (theTouchs[0].phase == TouchPhase.Ended || theTouchs[1].phase == TouchPhase.Ended) { pinchData[0].zero(); pinchData[1].zero(); return; } } else if (Input.touchCount == 1 && pinchHasFinished) { // get the touch data if one finger is touching the screen theTouch = Input.GetTouch(0); if (theTouch.phase == TouchPhase.Began) { // get the touch began and store the touch location moveData.firstTouch = theTouch.position; // Camera.main.ScreenToWorldPoint(VScreen); } if (theTouch.phase == TouchPhase.Ended) { // get the touch Ended and store the touch location moveData.lastTouch = theTouch.position; // Camera.main.ScreenToWorldPoint(VScreen); // get the time the the touch ended timeTouchEnded = Time.time; // get the distance the finger moved between the first and last touch. float distance = Vector3.Distance(moveData.firstTouch, moveData.lastTouch); // check if it moved over the mimimum distance if (distance > minimumSwipeDistance) { // then invoke the Onswipe event. OnSwipe?.Invoke(this, new directionMoveArgs(moveData, useCardinalDirectionForSwipe)); // zero data moveData.zero(); } else if (Time.time - timeTouchEnded < touchPressTime) { // if the not a swipe OnPress?.Invoke(this, EventArgs.Empty); } } } // mouse debuging if (mouseTesting) { MouseDebug(); } base.Update(); }
private void HandleOnPinch(Vector vector, bool isLeft) { OnPinch?.Invoke(this, new LeapEvent((int)vector.x, (int)vector.y, isLeft)); }