예제 #1
0
    protected void Update()
    {
        if (CustomInput.touchCount != 0 && !Match3BoardGameLogic.Instance.loseConditions.IsPaused)
        {
            touchInfo = CustomInput.GetTouch(0);

//			Debug.LogWarning("Touchphase: " + touchInfo.phase);

            float deltaMagnitude = touchInfo.deltaPosition.magnitude;

//			Debug.LogWarning("DELTA: " + deltaMagnitude + " " + lerpTreshold);

            if (interpolate && oldTouchPosition != POZ_UNASIGNED && deltaMagnitude > lerpTreshold)
            {
                float lerpAmount = lerpTreshold / deltaMagnitude;

                for (float lerpIndex = 0f; lerpIndex < 1; lerpIndex = Mathf.Clamp01(lerpIndex + lerpAmount))
                {
                    Vector3 lerpedPosition = Vector3.Lerp(oldTouchPosition, touchInfo.position, lerpIndex);
//					Debug.LogWarning("Lerped: " + lerpedPosition.ToString());
                    CheckBoardTouch(lerpedPosition, touchInfo);
                }
            }
            else
            {
                CheckBoardTouch(touchInfo.position, touchInfo);
            }

            oldTouchPosition = touchInfo.position;
        }
    }
예제 #2
0
    /// <summary>
    /// Checks the input. Call this at every frame or just when you needed. Register to this instance's events to get notified when they happen.
    /// </summary>
    public void CheckInput()
    {
        for (int i = 0; i < CustomInput.touchCount; ++i)
        {
            CustomInput.TouchInfo touch = CustomInput.GetTouch(i);

            if (touch.phase == TouchPhase.Began)
            {
                if (OnTapBegan != null)
                {
                    OnTapBegan(touch.position);
                }
            }
            else if (touch.phase == TouchPhase.Ended)
            {
                if (OnTapEnded != null)
                {
                    OnTapEnded(touch.position);
                }

                if (Time.time - touch.beginTime < SWIPE_MAX_TIME)
                {
                    if (OnSwipeLeftRight != null && touch.position.x - touch.beginPosition.x >= SWIPE_MIN_SCREEN * Screen.width)
                    {
                        OnSwipeLeftRight(touch.beginPosition, touch.position);
                    }
                    if (OnSwipeRightLeft != null && touch.position.x - touch.beginPosition.x <= -SWIPE_MIN_SCREEN * Screen.width)
                    {
                        OnSwipeRightLeft(touch.beginPosition, touch.position);
                    }
                }
            }
        }
    }
예제 #3
0
    //Coroutine for getting the input
    protected IEnumerator GetInput()
    {
        yield return(null);

        while (true)
        {
            if (CustomInput.touchCount != 0)
            {
                CustomInput.TouchInfo touch = CustomInput.GetTouch(0);

                if (touch.phase == TouchPhase.Ended && endPosition == Vector3.zero)
                {
                    startPosition = Vector3.zero;
                }

                if (touch.phase == TouchPhase.Ended && endPosition != Vector3.zero)
                {
                    touchController.StopInputController();
                    touchController.OnNewBoardPieceSelected -= OnNewBoardPieceSelected;

                    OnInputReceived();
                    yield break;
                }
            }

            yield return(null);
        }
    }