private void DragStart(Vector3 pos, bool isLongTap, bool isInitialDrag) { if (OnDragStart != null) { OnDragStart(pos, isLongTap); } isClickPrevented = true; timeSinceDragStart = 0; DragFinalMomentumVector.Clear(); }
private void DragStart(Vector3 pos) { if (OnDragStart != null) { OnDragStart(pos); } isClickPrevented = true; timeSinceDragStart = 0; DragFinalMomentumVector.Clear(); }
private void DragStart(Vector3 pos) { if (OnDragStart != null && !MobileTouchCamera.checkCamFollow) { OnDragStart(pos); } isClickPrevented = true; timeSinceDragStart = 0; DragFinalMomentumVector.Clear(); OpenDialog.instance.Close(); }
private void DragStop(Vector3 pos) { if (OnDragStop != null) { Vector3 momentum = Vector3.zero; if (DragFinalMomentumVector.Count > 0) { for (int i = 0; i < DragFinalMomentumVector.Count; ++i) { momentum += DragFinalMomentumVector[i]; } momentum /= DragFinalMomentumVector.Count; } OnDragStop(pos, momentum); } DragFinalMomentumVector.Clear(); }
private void DragStop(Vector3 pos) { if (OnDragStop != null && !MobileTouchCamera.checkCamFollow) { Vector3 momentum = Vector3.zero; if (DragFinalMomentumVector.Count > 0) { for (int i = 0; i < DragFinalMomentumVector.Count; ++i) { momentum += DragFinalMomentumVector[i]; } momentum /= DragFinalMomentumVector.Count; } OnDragStop(pos, momentum); } DragFinalMomentumVector.Clear(); }
public void Update() { if (TouchWrapper.IsFingerDown == false) { isInputOnLockedArea = false; } bool pinchToDragCurrentFrame = false; if (isInputOnLockedArea == false) { #region pinch if (isPinching == false) { if (TouchWrapper.TouchCount == 2) { StartPinch(); isPinching = true; } } else { if (TouchWrapper.TouchCount < 2) { StopPinch(); isPinching = false; } else if (TouchWrapper.TouchCount == 2) { UpdatePinch(); } } #endregion #region drag if (isPinching == false) { if (wasPinchingLastFrame == false) { if (wasFingerDownLastFrame == true && TouchWrapper.IsFingerDown) { if (isDragging == false) { float dragDistance = GetRelativeDragDistance(TouchWrapper.Touch0.Position, dragStartPos); float dragTime = Time.realtimeSinceStartup - lastFingerDownTimeReal; bool isLongTap = dragTime > clickDurationThreshold; if (OnLongTapProgress != null) { float longTapProgress = 0; if (Mathf.Approximately(clickDurationThreshold, 0) == false) { longTapProgress = Mathf.Clamp01(dragTime / clickDurationThreshold); } OnLongTapProgress(longTapProgress); } if ((dragDistance >= dragStartDistanceThresholdRelative && dragTime >= dragDurationThreshold) || (longTapStartsDrag == true && isLongTap == true)) { isDragging = true; dragStartOffset = lastFinger0DownPos - dragStartPos; dragStartPos = lastFinger0DownPos; DragStart(dragStartPos, isLongTap, true); } } } } else { if (TouchWrapper.IsFingerDown == true) { isDragging = true; dragStartPos = TouchWrapper.Touch0.Position; DragStart(dragStartPos, false, false); pinchToDragCurrentFrame = true; } } if (isDragging == true && TouchWrapper.IsFingerDown == true) { DragUpdate(TouchWrapper.Touch0.Position); } if (isDragging == true && TouchWrapper.IsFingerDown == false) { isDragging = false; DragStop(lastFinger0DownPos); } } #endregion #region click if (isPinching == false && isDragging == false && wasPinchingLastFrame == false && wasDraggingLastFrame == false && isClickPrevented == false) { if (wasFingerDownLastFrame == false && TouchWrapper.IsFingerDown) { lastFingerDownTimeReal = Time.realtimeSinceStartup; dragStartPos = TouchWrapper.Touch0.Position; FingerDown(TouchWrapper.AverageTouchPos); } if (wasFingerDownLastFrame == true && TouchWrapper.IsFingerDown == false) { float fingerDownUpDuration = Time.realtimeSinceStartup - lastFingerDownTimeReal; if (wasDraggingLastFrame == false && wasPinchingLastFrame == false) { float clickDuration = Time.realtimeSinceStartup - lastClickTimeReal; bool isDoubleClick = clickDuration < doubleclickDurationThreshold; bool isLongTap = fingerDownUpDuration > clickDurationThreshold; if (OnInputClick != null) { OnInputClick.Invoke(lastFinger0DownPos, isDoubleClick, isLongTap); } lastClickTimeReal = Time.realtimeSinceStartup; } } } #endregion } if (isDragging && TouchWrapper.IsFingerDown && pinchToDragCurrentFrame == false) { DragFinalMomentumVector.Add(TouchWrapper.Touch0.Position - lastFinger0DownPos); if (DragFinalMomentumVector.Count > momentumSamplesCount) { DragFinalMomentumVector.RemoveAt(0); } } if (isInputOnLockedArea == false) { wasFingerDownLastFrame = TouchWrapper.IsFingerDown; } if (wasFingerDownLastFrame == true) { lastFinger0DownPos = TouchWrapper.Touch0.Position; } wasDraggingLastFrame = isDragging; wasPinchingLastFrame = isPinching; if (TouchWrapper.TouchCount == 0) { isClickPrevented = false; if (isFingerDown == true) { FingerUp(); } } }
public void Update() { if (TouchWrapper.IsFingerDown == false) { isInputOnLockedArea = false; } bool pinchToDragCurrentFrame = false; if (isInputOnLockedArea == false) { #region pinch if (isPinching == false) { if (TouchWrapper.TouchCount == 2) { StartPinch(); isPinching = true; } } else { if (TouchWrapper.TouchCount < 2) { StopPinch(); isPinching = false; } else if (TouchWrapper.TouchCount == 2) { UpdatePinch(); } } #endregion #region drag if (isPinching == false) { if (wasPinchingLastFrame == false) { if (wasFingerDownLastFrame == true && TouchWrapper.IsFingerDown) { if (isDragging == false) { Vector2 dragVector = TouchWrapper.Touch0.Position - dragStartPos; float dragDistance = new Vector2(dragVector.x / Screen.width, dragVector.y / Screen.height).magnitude; float dragTime = Time.realtimeSinceStartup - lastFingerDownTimeReal; if ((dragDistance >= dragStartDistanceThresholdRelative && dragTime >= dragDurationThreshold) || dragTime > doubleclickDurationThreshold) { isDragging = true; dragStartOffset = lastFinger0DownPos - dragStartPos; dragStartPos = lastFinger0DownPos; DragStart(dragStartPos); } } } } else { if (TouchWrapper.IsFingerDown == true) { isDragging = true; dragStartPos = TouchWrapper.Touch0.Position; DragStart(dragStartPos); pinchToDragCurrentFrame = true; } } if (isDragging == true && TouchWrapper.IsFingerDown == true) { DragUpdate(TouchWrapper.Touch0.Position); } if (isDragging == true && TouchWrapper.IsFingerDown == false) { isDragging = false; DragStop(lastFinger0DownPos); } } #endregion #region click if (isPinching == false && isDragging == false && wasPinchingLastFrame == false && wasDraggingLastFrame == false && isClickPrevented == false) { if (wasFingerDownLastFrame == false && TouchWrapper.IsFingerDown) { lastFingerDownTimeReal = Time.realtimeSinceStartup; dragStartPos = TouchWrapper.Touch0.Position; FingerDown(TouchWrapper.AverageTouchPos); } if (wasFingerDownLastFrame == true && TouchWrapper.IsFingerDown == false) { float fingerDownUpDuration = Time.realtimeSinceStartup - lastFingerDownTimeReal; if (fingerDownUpDuration < clickDurationThreshold) { if (wasDraggingLastFrame == false && wasPinchingLastFrame == false) { float clickDuration = Time.realtimeSinceStartup - lastClickTimeReal; bool isDoubleClick = clickDuration < doubleclickDurationThreshold; if (OnInputClick != null) { OnInputClick.Invoke(lastFinger0DownPos, isDoubleClick); } lastClickTimeReal = Time.realtimeSinceStartup; } } } } #endregion } if (isDragging && TouchWrapper.IsFingerDown && pinchToDragCurrentFrame == false) { DragFinalMomentumVector.Add(TouchWrapper.Touch0.Position - lastFinger0DownPos); if (DragFinalMomentumVector.Count > momentumSamplesCount) { DragFinalMomentumVector.RemoveAt(0); } } wasFingerDownLastFrame = TouchWrapper.IsFingerDown; if (wasFingerDownLastFrame == true) { lastFinger0DownPos = TouchWrapper.Touch0.Position; } wasDraggingLastFrame = isDragging; wasPinchingLastFrame = isPinching; if (TouchWrapper.TouchCount == 0) { isClickPrevented = false; if (isFingerDown == true) { FingerUp(); } } }