public void OnPointerExit(PointerEventData eventData)
        {
            Vector2 swipe = (eventData.position - swipeStartPos);

            if (allowVertical)
            {
                if (eventData.position.y < swipeStartPos.y && Mathf.Abs(Mathf.DeltaAngle(Vector2.Angle(Vector2.up, swipe), 180f)) < maximumAngle)
                {
                    swipeDir = SwipeDir.Down;
                }
                else if (Mathf.Abs(Mathf.DeltaAngle(Vector2.Angle(Vector2.up, swipe), 0f)) < maximumAngle)
                {
                    swipeDir = SwipeDir.Up;
                }
            }
            if (allowHorizontal)
            {
                if (eventData.position.x < swipeStartPos.x && Mathf.Abs(Mathf.DeltaAngle(Vector2.Angle(Vector2.up, swipe), 90f)) < maximumAngle)
                {
                    swipeDir = SwipeDir.Left;
                }
                else if (Mathf.Abs(Mathf.DeltaAngle(Vector2.Angle(Vector2.up, swipe), 90f)) < maximumAngle)
                {
                    swipeDir = SwipeDir.Right;
                }
            }
        }
        private void Update()
        {
            if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
            {
                swipeStartTime = Time.time;
            }
            else if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended)
            {
                Vector2 swipe = (Input.GetTouch(0).position - swipeStartPos);
                if ((Time.time - swipeStartTime) < swipeMaximumDuration && swipe.magnitude > requiredMaginitude)
                {
                    switch (swipeDir)
                    {
                    case SwipeDir.Up:
                        OnSwipeUp.Invoke();
                        break;

                    case SwipeDir.Down:
                        OnSwipeDown.Invoke();
                        break;

                    case SwipeDir.Left:
                        OnSwipeLeft.Invoke();
                        break;

                    case SwipeDir.Right:
                        OnSwipeRight.Invoke();
                        break;
                    }
                }
                // Make sure this swipe is no longer valid for future touch ups
                swipeDir       = SwipeDir.None;
                swipeStartTime = Time.time - swipeMaximumDuration;
            }
        }
Esempio n. 3
0
    private void Update()
    {
        Dir = SwipeDir.None;

        if (Input.GetMouseButtonDown(0))
        {
            touchPos = Input.mousePosition;
        }

        if (Input.GetMouseButtonUp(0))
        {
            Vector2 deltaSwipe = touchPos - Input.mousePosition;
            if (Mathf.Abs(deltaSwipe.x) > swipeResX)
            {
                Dir |= (deltaSwipe.x < 0) ? SwipeDir.Right : SwipeDir.Left;
            }
            if (Mathf.Abs(deltaSwipe.y) > swipeResY)
            {
                Dir |= (deltaSwipe.y < 0) ? SwipeDir.Up : SwipeDir.Down;
            }
        }
    }
Esempio n. 4
0
    private void SendSwipe(SwipeDir direction)
    {
        switch (direction)
        {
        case SwipeDir.Up:
            MovePlayer(new Vector3(1, 0, 0));
            break;

        case SwipeDir.Down:
            MovePlayer(new Vector3(-1, 0, 0));
            break;

        case SwipeDir.Left:
            MovePlayer(new Vector3(0, 0, 1));
            break;

        case SwipeDir.Right:
            MovePlayer(new Vector3(0, 0, -1));
            break;

        default:
            break;
        }
    }
    void FixedUpdate()
    {
        if (rTouchArea == true)
        {
            curSwipeDir = SwipeDir.Right;
        }
        if (lTouchArea == true)
        {
            curSwipeDir = SwipeDir.Left;
        }
        if (rTouchArea == false && lTouchArea == false)
        {
            curSwipeDir = SwipeDir.None;
        }
        //#if UNITY_ANDROID
        if (Input.touchCount > 0)
        {
            foreach (Touch iTouch in Input.touches)
            {
                Touch touch = iTouch;

                switch (touch.phase)

                {
                case TouchPhase.Began:
                    startPos = touch.position;

                    Debug.Log(startPos);

                    if (startPos.x > StrafeArea && startPos.x < Screen.width - StrafeArea)
                    {
                        foreach (Controller contr in controller)
                        {
                            contr.Jump();
                        }
                    }

                    if (startPos.x < StrafeArea)
                    {
                        lTouchArea = true;
                    }

                    if (startPos.x > Screen.width - StrafeArea)
                    {
                        rTouchArea = true;
                    }
                    break;

                case TouchPhase.Ended:

//					float swipeDistVertical = (new Vector3(0, touch.position.y, 0) - new Vector3(0, startPos.y, 0)).magnitude;
//
//					float swipeDistHorizontal = (new Vector3(touch.position.x,0, 0) - new Vector3(startPos.x, 0, 0)).magnitude;
//
//					if (swipeDistVertical > minSwipeDistY && swipeDistVertical > swipeDistHorizontal
//					    && startPos.x > StrafeArea && startPos.x < Screen.width - StrafeArea)
//					{
//						float swipeValue = Mathf.Sign(touch.position.y - startPos.y);
//
//						if (swipeValue > 0)//up swipe
//						{
//							foreach(Controller contr in controller)
//								contr.Jump();
//						}
//
//						else if (swipeValue < 0)//down swipe
//							return;
//					}

                    if (touch.position.x < StrafeArea)
                    {
                        lTouchArea = false;
                    }

                    if (touch.position.x > Screen.width - StrafeArea)
                    {
                        rTouchArea = false;
                    }

                    //				if (swipeDistHorizontal > minSwipeDistX && swipeDistHorizontal > swipeDistVertical)
                    //
                    //				{
                    //
                    //					float swipeValue = Mathf.Sign(touch.position.x - startPos.x);
                    //
                    //					if (swipeValue > 0)//right swipe
                    //					{
                    //						curSwipeDir = SwipeDir.Right;
                    //
                    //						foreach(Controller contr in controller)
                    //							contr.Locomotion();
                    //					}
                    //
                    //					else if (swipeValue < 0)//left swipe
                    //					{
                    //						curSwipeDir = SwipeDir.Left;
                    //
                    //						foreach(Controller contr in controller)
                    //							contr.Locomotion();
                    //					}
                    //
                    //				}
                    break;
                }
            }
        }
    }
Esempio n. 6
0
	public void OnSwiped (SwipeDir dir,Vector2 startPos,Vector2 endPos,float velocity,float distance)
	{
		Swiped (dir, startPos, endPos, velocity, distance);
	}
Esempio n. 7
0
	/*
	-----------------------
	GetSwipeDirection()
	-----------------------
	*/
	bool GetSwipeDirection (Vector2 delta, out SwipeDir swipeDirection)
	{
		float minSwipeDot = Mathf.Clamp01 (1.0f - swipeDirectionTolerance); 
		Vector2 dir = delta.normalized;
		if (Vector2.Dot (dir, Vector2.right) >= minSwipeDot)
			swipeDirection = SwipeDir.Right;
		else if (Vector2.Dot (dir, -Vector2.right) >= minSwipeDot)
			swipeDirection = SwipeDir.Left;
		else if (Vector2.Dot (dir, Vector2.up) >= minSwipeDot)
			swipeDirection = SwipeDir.Up;
		else if (Vector2.Dot (dir, -Vector2.up) >= minSwipeDot)
			swipeDirection = SwipeDir.Down;
		else {
			swipeDirection = SwipeDir.Invalid;
		}
		return (swipeDirection != SwipeDir.Invalid);		
	}
Esempio n. 8
0
 public bool IsSwiping(SwipeDir dir)
 {
     return((Dir & dir) == dir);
 }