Beispiel #1
0
    public override void Apply(TouchEvent touchEvent)
    {
        if (!swipeStarted && CheckForSwipeStart(touchEvent))
        {
            StartSwipe(touchEvent);
        }
        //Note this is not an else-if because a swipe can potentially start and end on the same frame
        if (swipeStarted && touchEvent.GetCurrentState() == TouchPhase.Ended)
        {
            if (CheckForSwipeEnd(touchEvent))
            {
                hero.ClearAnimationState();
                StartCoroutine(DrawSwipeAttack(touchEvent));
            }
            else
            {
                cancelSwipe();
            }
        }

        if (swipeStarted && touchEvent.GetCurrentState() == TouchPhase.Canceled)
        {
            cancelSwipe();
        }
    }
Beispiel #2
0
    private bool CheckForSwipeStart(TouchEvent touchEvent)
    {
        if (touchEvent.GetCurrentState() != TouchPhase.Moved && touchEvent.GetCurrentState() != TouchPhase.Ended)
        {
            return(false);
        }

        Vector2 totalDistance = touchEvent.GetTouchEventPositionDelta();

        return(totalDistance.magnitude >= minSwipeDistance);
    }
Beispiel #3
0
 public override void Apply(TouchEvent touchEvent)
 {
     if (touchEvent.GetCurrentState() == TouchPhase.Ended && IsTap(touchEvent))
     {
         Vector3 target;
         if (TouchUtils.TouchPositionToWorldCoords(touchEvent.GetStartPosition(), out target, hero.transform.position.y))
         {
             hero.MoveToTarget(target);
         }
     }
 }