protected void Acquire(TouchManager.Finger finger) { if (!finger.GestureRecognizers.Contains(this)) { finger.GestureRecognizers.Add(this); } }
void UpdatePerFinger() { for (int i = 0; i < TouchManager.Instance.MaxFingers && i < MaxSimultaneousGestures; ++i) { TouchManager.Finger finger = TouchManager.GetFinger(i); T gesture = gestures[i]; TouchManager.FingerList touches = tempTouchList; touches.Clear(); if (finger.IsDown) { touches.Add(finger); } if (gesture.State == GestureRecognitionState.Ready) { if (CanBegin(gesture, touches)) { Begin(gesture, 0, touches); } } UpdateGesture(gesture, touches); if ("OnEasyGesture" == gesture.Recognizer.EventMessageName) { if (touches.Count <= 0) { Reset(gesture, false); } } } }
/// tool protected bool Young(TouchManager.IFingerList touches) { TouchManager.Finger oldestTouch = touches.GetOldest(); if (oldestTouch == null) { return(false); } float elapsedTimeSinceFirstTouch = UnityEngine.Time.time - oldestTouch.StarTime; return(elapsedTimeSinceFirstTouch < 0.25f); }
protected override void ProcessFinger(TouchManager.Finger finger) { if (finger.IsDown && !finger.WasDown) { FingerDownEvent e = GetEvent(finger.Index); e.Name = MessageName; if (OnFingerDown != null) { OnFingerDown(e); } TrySendMessage(e); } }
protected override void ProcessFinger(TouchManager.Finger finger) { if (!finger.IsDown && finger.WasDown) { FingerUpEvent e = GetEvent(finger); e.Name = MessageName; e.TimeHeldDown = Mathf.Max(0, Time.time - finger.StarTime); if (OnFingerUp != null) { OnFingerUp(e); } TrySendMessage(e); /// UpdateRegognizerScript(); } }
protected override void ProcessFinger(TouchManager.Finger finger) { FingerMotionEvent e = GetEvent(finger); bool selectionUpdated = false; // 手指状态改变 if (finger.Phase != finger.PreviousPhase) { switch (finger.PreviousPhase) { case TouchManager.FingerPhase.Moving: selectionUpdated |= FireEvent(e, EventType.Move, FingerMotionPhase.Ended, finger.Position, !selectionUpdated); break; case TouchManager.FingerPhase.Stationary: selectionUpdated |= FireEvent(e, EventType.Stationary, FingerMotionPhase.Ended, finger.PreviousPosition, !selectionUpdated); break; } switch (finger.Phase) { case TouchManager.FingerPhase.Moving: selectionUpdated |= FireEvent(e, EventType.Move, FingerMotionPhase.Started, finger.PreviousPosition, !selectionUpdated); selectionUpdated |= FireEvent(e, EventType.Move, FingerMotionPhase.Updated, finger.Position, !selectionUpdated); break; case TouchManager.FingerPhase.Stationary: selectionUpdated |= FireEvent(e, EventType.Stationary, FingerMotionPhase.Started, finger.Position, !selectionUpdated); selectionUpdated |= FireEvent(e, EventType.Stationary, FingerMotionPhase.Updated, finger.Position, !selectionUpdated); break; } } else { // 手指状态一直一样 switch (finger.Phase) { case TouchManager.FingerPhase.Moving: selectionUpdated |= FireEvent(e, EventType.Move, FingerMotionPhase.Updated, finger.Position, !selectionUpdated); break; case TouchManager.FingerPhase.Stationary: selectionUpdated |= FireEvent(e, EventType.Stationary, FingerMotionPhase.Updated, finger.Position, !selectionUpdated); break; } } }
void Begin(T gesture, int clusterId, TouchManager.IFingerList touches) { gesture.ClusterId = clusterId; gesture.StartTime = UnityEngine.Time.time; #if UNITY_EDITOR if (gesture.Fingers.Count > 0) { //Debug.LogWarning("Begin Gesture Error"); } #endif for (int i = 0; i < touches.Count; ++i) { TouchManager.Finger finger = touches[i]; gesture.Fingers.Add(finger); Acquire(finger); } OnBegin(gesture, touches); gesture.State = GestureRecognitionState.Started; }
protected T GetEvent(TouchManager.Finger finger) { return(GetEvent(finger.Index)); }
public bool Release(TouchManager.Finger finger) { return(finger.GestureRecognizers.Remove(this)); }
void TraceFingers() { if (m_JoystickOperation) { return; } #if UNITY_EDITOR // Zoom Camera and keep the distance between [minDistance, maxDistance]. float mw = Input.GetAxis("Mouse ScrollWheel"); if (mw > 0) { m_CurDistance -= Time.deltaTime * m_ZoomSpeed; if (m_CurDistance < m_MinDistance) { m_CurDistance = m_MinDistance; } } else if (mw < 0) { m_CurDistance += Time.deltaTime * m_ZoomSpeed; if (m_CurDistance > m_MaxDistance) { m_CurDistance = m_MaxDistance; } } #endif TouchManager.FingerList touches = (TouchManager.FingerList)TouchManager.Touches; if (touches.Count == 1 && !m_InWatchMode) { if (m_Finger1 == null) { m_Finger1 = touches[0]; } float xDistance = m_Finger1.DeltaPosition.x; float yDistance = m_Finger1.DeltaPosition.y; float xMoveScaler = xDistance / UnityEngine.Screen.width; float yMoveScaler = yDistance / UnityEngine.Screen.height; TouchManager.Finger finger = touches[0]; if (finger.IsMoving) { float xScaleFactor = UnityEngine.Mathf.Abs(finger.DeltaPosition.x) / UnityEngine.Mathf.Abs(finger.DeltaPosition.y); xScaleFactor = xScaleFactor > 1.0f ? 1.0f : xScaleFactor; float yScaleFactor = UnityEngine.Mathf.Abs(finger.DeltaPosition.y) / UnityEngine.Mathf.Abs(finger.DeltaPosition.x); yScaleFactor = yScaleFactor > 1.0f ? 1.0f : yScaleFactor; if (finger.DeltaPosition.x > 0) { // Rotate Left // m_FixedYaw = m_CameraTransform.eulerAngles.y + m_AngularMaxSpeed * Time.deltaTime * xScaleFactor; m_FixedYaw = m_CameraTransform.eulerAngles.y + m_AngularMaxSpeed * 2.0f * xMoveScaler; } else if (finger.DeltaPosition.x < 0) { // Rotate Right // m_FixedYaw = m_CameraTransform.eulerAngles.y - m_AngularMaxSpeed * Time.deltaTime * xScaleFactor; m_FixedYaw = m_CameraTransform.eulerAngles.y + m_AngularMaxSpeed * 2.0f * xMoveScaler; } if (finger.DeltaPosition.y > 0) { // Rotate Down // float camXAngle = m_CameraTransform.eulerAngles.x - m_AngularMaxSpeed * Time.deltaTime * yScaleFactor; float camXAngle = m_CameraTransform.eulerAngles.x - m_AngularMaxSpeed * 0.6f * yMoveScaler; if (camXAngle < m_MinCameraAngle) { camXAngle = m_MinCameraAngle; } m_FixedRoll = camXAngle; } else if (finger.DeltaPosition.y < 0) { // Rotate Up // float camXAngle = m_CameraTransform.eulerAngles.x + m_AngularMaxSpeed * Time.deltaTime * yScaleFactor; float camXAngle = m_CameraTransform.eulerAngles.x - m_AngularMaxSpeed * 0.6f * yMoveScaler; if (camXAngle > m_MaxCameraAngle) { camXAngle = m_MaxCameraAngle; } m_FixedRoll = camXAngle; } } } else if (touches.Count == 2) { m_Finger1 = null; TouchManager.Finger finger1 = touches[0]; TouchManager.Finger finger2 = touches[1]; if ((finger1.IsDown && !finger1.WasDown) || (finger2.IsDown && !finger2.WasDown)) { m_FingerDistance = UnityEngine.Vector2.Distance(finger1.StartPosition, finger2.StartPosition); } if (finger1.IsMoving || finger2.IsMoving) { float currentDistance = UnityEngine.Vector2.Distance(finger1.Position, finger2.Position); if (currentDistance > m_FingerDistance) { // Zoom In m_CurDistance -= Time.deltaTime * m_ZoomSpeed; if (m_CurDistance < m_MinDistance) { m_CurDistance = m_MinDistance; } } else if (currentDistance < m_FingerDistance) { // Zoom Out m_CurDistance += Time.deltaTime * m_ZoomSpeed; if (m_CurDistance > m_MaxDistance) { m_CurDistance = m_MaxDistance; } } m_FingerDistance = currentDistance; } } else { m_Finger1 = null; } }