Пример #1
0
    /// <summary>
    /// 手势识别
    /// </summary>
    protected override GestureState OnRecognize(DragPressGesture gesture, IFingerList touches)
    {
        if (touches.Count != RequiredFingerCount)
        {
            // fingers were lifted off
            if (touches.Count < RequiredFingerCount)
            {
                return(GestureState.Ended);
            }

            return(GestureState.Failed);
        }

        if (RequiredFingerCount >= 2 &&
            touches.AllMoving() && !touches.MovingInSameDirection(0.35f))
        {
            return(GestureState.Failed);
        }

        gesture.position  = touches.GetAveragePosition();
        gesture.LastDelta = gesture.DeltaMove;
        gesture.DeltaMove = gesture.position - gesture.LastPos;

        if (gesture.DeltaMove.sqrMagnitude > 0 || gesture.LastDelta.sqrMagnitude > 0)
        {
            gesture.LastPos = gesture.position;
        }

        RaiseEvent(gesture);
        return(GestureState.InProgress);
    }
Пример #2
0
 /// <summary>
 /// 手势开始
 /// </summary>
 protected override void OnBegin(DragPressGesture gesture, IFingerList touches)
 {
     gesture.position      = touches.GetAveragePosition();
     gesture.startPosition = touches.GetAverageStartPosition();
     gesture.DeltaMove     = gesture.position - gesture.startPosition;
     gesture.LastDelta     = Vector2.zero;
     gesture.LastPos       = gesture.position;
 }
Пример #3
0
    /// ---------------------------------------------------------------------------------
    /// <summary>
    /// 判断手势是否可以开始
    /// </summary>
    /// ---------------------------------------------------------------------------------
    protected virtual bool CanBegin(T gesture, IFingerList touches)
    {
        if (touches.Count != RequiredFingerCount)
        {
            return(false);
        }

        return(true);
    }
Пример #4
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// 判断手势的状态
 /// </summary>
 /// ------------------------------------------------------------------------------------
 protected virtual void UpdateGesture(T gesture, IFingerList touches)
 {
     /*
      * if (gesture.State == GestureState.Ready)
      * return;
      *
      * if (gesture.State == GestureState.Started)
      * gesture.State = GestureState.InProgress;
      *
      * switch (gesture.State)
      * {
      * case GestureState.InProgress:
      * {
      *  GestureState newState = OnRecognize(gesture, touches);
      *  if (newState == GestureState.FailAndRetry)
      *  {
      *      gesture.State = GestureState.Failed;
      *      Reset(gesture);
      *
      *      if (CanBegin(gesture, touches))
      *      {
      *          Begin(gesture, touches);
      *      }
      *  }
      *  else
      *  {
      *      if (newState == GestureState.InProgress)
      *      {
      *          //gesture.PickStartSelection(Raycaster);
      *      }
      *
      *      gesture.State = newState;
      *  }
      * }
      * break;
      *
      * case GestureState.Recognized:
      * case GestureState.Failed:
      * {
      *  RaiseEvent(gesture);
      *  Reset(gesture);
      * }
      * break;
      *
      * default:
      * Debug.LogError("Unhandled state" + gesture.State);
      * gesture.State = GestureState.Failed;
      * break;
      *
      * }
      */
 }
Пример #5
0
    protected override GestureState OnRecognize(TapGesture gesture, IFingerList touches)
    {
        if (touches.Count != 1)
        {
            return(GestureState.Failed);
        }

        if (gesture.deltaTime <= Duration)
        {
            return(GestureState.Recognized);
        }

        return(GestureState.InProgress);
    }
Пример #6
0
 protected override GestureState OnRecognize(LongPressGesture gesture, IFingerList touches)
 {
     /*
      * if (touches.Count != 1)
      * return GestureState.Failed;
      *
      * if (gesture.deltaTime >= Duration)
      * return GestureState.Recognized;
      *
      * if (touches.GetAverageDistanceFromStart() > ToPixels(MoveTolerance))
      * return GestureState.Failed;
      */
     return(GestureState.InProgress);
 }
Пример #7
0
    /// ---------------------------------------------------------------------------------
    /// <summary>
    /// 计算当前所有的手指的情况
    /// </summary>
    /// ---------------------------------------------------------------------------------
    public virtual void UpdateExclusive()
    {
        T           pGest   = _gestures[0];
        IFingerList touches = EasyFingerGestues.instance.mTouches;

        if (pGest.state == GestureState.Ready)
        {
            if (CanBegin(pGest, touches))
            {
                Begin(pGest, touches);
            }
        }

        UpdateGesture(pGest, touches);
    }
Пример #8
0
 protected override bool CanBegin(DragPressGesture gesture, IFingerList touches)
 {
     /*
      * if (!base.CanBegin(gesture, touches))
      * return false;
      *
      * if (touches.GetAverageDistanceFromStart() < ToPixels(MoveTolerance))
      * return false;
      *
      * if (!touches.AllMoving())
      * return false;
      *
      * if (RequiredFingerCount >= 2 && !touches.MovingInSameDirection(0.35f))
      * return false;
      */
     return(true);
 }
Пример #9
0
    /// ---------------------------------------------------------------------------------
    /// <summary>
    /// 根据射线检测,手势与GameObject 是否有碰撞,来更新手势的状态
    /// </summary>
    /// ---------------------------------------------------------------------------------
    void Begin(T gesture, IFingerList touches)
    {
        gesture.startTime = Time.time;
#if UNITY_EDITOR
        if (gesture.Fingers.Count > 0)
        {
            Debug.Log("egin gesture with fingers list not properly released");
        }
#endif

        for (int i = 0; i < touches.Count; ++i)
        {
            Finger finger = touches[i];
            gesture.Fingers.Add(finger);
        }

        OnBegin(gesture, touches);
        gesture.state = GestureState.Started;
    }
Пример #10
0
 protected override void OnBegin(TapGesture gesture, IFingerList touches)
 {
 }
Пример #11
0
 protected override void OnBegin(LongPressGesture gesture, IFingerList touches)
 {
     gesture.position      = touches.GetAveragePosition();
     gesture.startPosition = touches.GetAverageStartPosition();
 }
Пример #12
0
 /// <summary>
 /// 手势识别
 /// </summary>
 protected override GestureState OnRecognize(CirclePressGesture gesture, IFingerList touches)
 {
     return(GestureState.InProgress);
 }
Пример #13
0
 /// <summary>
 /// 手势开始
 /// </summary>
 protected override void OnBegin(CirclePressGesture gesture, IFingerList touches)
 {
 }
Пример #14
0
 /// ---------------------------------------------------------------------------------
 /// <summary>
 /// 手势可以开识别处理, 子类中必须实现
 /// </summary>
 /// ---------------------------------------------------------------------------------
 protected abstract GestureState OnRecognize(T gesture, IFingerList touches);
Пример #15
0
 /// ---------------------------------------------------------------------------------
 /// <summary>
 /// 手势可以开始识别, 子类中必须实现
 /// </summary>
 /// ---------------------------------------------------------------------------------
 protected abstract void OnBegin(T gesture, IFingerList touches);