private void InputHandler() { /* HANDLE most recent touch---------------------------------------------------------- -*/ switch (lastTouch.phase) { case TouchPhase.Began: firstPosTouch = lastTouch.position; break; case TouchPhase.Moved: if ( Mathf.Abs(PosTouchRatioX(firstPosTouch.x) - PosTouchRatioX(lastTouch.position.x)) > swipeAcceptance || Mathf.Abs(PosTouchRatioY(firstPosTouch.y) - PosTouchRatioY(lastTouch.position.y)) > swipeAcceptance ) { if (touchHandle.IsInLeftSide(lastTouch.position)) { // TO DO SLIDE LEFT // isPrepaNeutralJumping = false; inputPressed = true; if (isGrounded) { if (GetSpeed() >= maxSpeed) { isSuperJumping = true; SuperJump(-1); break; } isClassicJumping = true; Jump(-1); break; } } if (touchHandle.IsInRightSide(lastTouch.position)) { // TO DO SLIDE RIGHT // isPrepaNeutralJumping = false; inputPressed = true; if (isGrounded) { if (GetSpeed() >= maxSpeed) { isSuperJumping = true; SuperJump(1); break; } isClassicJumping = true; Jump(1); break; } } } break; case TouchPhase.Stationary: if (Input.touchCount > 1 && touches[Input.touchCount - 2].phase == TouchPhase.Stationary) { //DOUBLE PRESS // Debug.Log("DOUBLE PRESS"); // Debug.Log("DOUBLE PRESS WITHIN double Tap Acceptance(" + doubleTapAcceptance + ") tlast: " + lastTouchTimePress + " tfirst: " + firstTouchTimePress); if ( (touchHandle.IsInLeftSide(lastTouch.position) && touchHandle.IsInRightSide(touches[Input.touchCount - 2].position)) || (touchHandle.IsInRightSide(lastTouch.position) && touchHandle.IsInLeftSide(touches[Input.touchCount - 2].position)) && Mathf.Abs(lastTouchTimePress - firstTouchTimePress) <= doubleTapAcceptance ) { //TO DO DOUBLE PRESS // Debug.Log("DOUBLE PRESS WITHIN double Tap Acceptance(" + doubleTapAcceptance + ") tlast: " + lastTouchTimePress + " tfirst: " + firstTouchTimePress); // inputPressed = true; // DoubleTapPressHandler(); break; } } if (touchHandle.IsInLeftSide(lastTouch.position)) { //TO DO PRESS LEFT //isPrepaNeutralJumping = false; inputPressed = true; if (!isGrounded) { if (rb.velocity.y < 0) //BLOUPY IS FALLING { if (transform.localScale.x > 0 && transform.position.x > originalPos.x) //sprite to the right { // AIR CONTROL LEFT Move(-Mathf.Abs(aircontrol)); } break; } } else { MoveLeft(); } break; } if (touchHandle.IsInRightSide(lastTouch.position)) { //TO DO PRESS RIGHT // isPrepaNeutralJumping = false; inputPressed = true; if (!isGrounded) { if (rb.velocity.y < 0) //BLOUPY IS FALLING { if (transform.localScale.x < 0 && transform.position.x < originalPos.x) //sprite to the left { // AIR CONTROL right Move(Mathf.Abs(aircontrol)); } break; } } else { MoveRight(); } break; } break; case TouchPhase.Ended: lastTouchTimeRelease = Time.time; /* * if (Mathf.Abs(touchTimeReleaseLeft - touchTimeReleaseRight) <= doubleTapAcceptance) * { * if ((Time.time - touchTimePressRight > neutralJumpMinimumHolding) || (Time.time - touchTimePressLeft > neutralJumpMinimumHolding)) * { * DoubleTapReleaseHandler(); * } * isPrepaNeutralJumping = false; * break; * } * * * //touchTimesRelease[0] = Time.time; * * if (Input.touchCount > 1) * { * if ( * (touchHandle.IsInLeftSide(lastTouch.position) && touchHandle.IsInRightSide(touches[Input.touchCount - 2].position)) || || (touchHandle.IsInLeftSide(touches[Input.touchCount - 2].position) || touchHandle.IsInRightSide(lastTouch.position)) || && || Mathf.Abs(touchTimesPress[0] - touchTimesPress[1]) <= doubleTapAcceptance || ) || { || lastTouchTimeRelease = Time.time; || || if (Mathf.Abs(lastTouchTimeRelease - firstTouchTimeRelease) <= doubleTapAcceptance) || { || DoubleTapReleaseHandler(); || } || break; || } || isPrepaNeutralJumping = false; || break; ||} || ||if (Time.time - firstTouchTimeRelease < doubleTapAcceptance) ||{ || // DOUBLE TAPP RELEASE || DoubleTapReleaseHandler(); || break; ||} ||if (touchHandle.IsInLeftSide(lastTouch.position)) ||{ || //TO DO RELEASE LEFT || // Debug.Log("RELEASE LEFT "); || isPrepaNeutralJumping = false; || break; ||} ||if (touchHandle.IsInRightSide(lastTouch.position)) ||{ || //TO DO RELEASE RIGHT || // Debug.Log("RELEASE RIGHT "); || isPrepaNeutralJumping = false; || || break; ||}*/ break; case TouchPhase.Canceled: break; default: inputPressed = false; break; } }
void InputHandler() { if (Input.touchCount != 0) { foreach (var it in Input.touches) { if (touchHandle.IsInLeftSide(it.position)) { currenttouch = it; // Debug.Log("LEFT"); switch (currenttouch.phase) { case TouchPhase.Began: // Debug.Log("LEFT BEGAN"); pressTime = Time.time; pressPos = it.position; break; case TouchPhase.Moved: // Debug.Log("LEFT MOVED"); if (!movementBloupy.GetIsGrounded()) { if (movementBloupy.rb.velocity.y < 0) //BLOUPY IS FALLING { // if (transform.localScale.x < 0 && transform.position.x > movementBloupy.originalPos.x) //sprite to the right // { // AIR CONTROL LEFT movementBloupy.Move(-Mathf.Abs(movementBloupy.aircontrol)); // } break; } } if (movementBloupy.GetIsPrepaNeutralJumping()) { break; } /*SWIPE HANDLER---------------------------------------------------*/ float xZero = movementBloupy.PosTouchRatioX(pressPos.x); float xUn = movementBloupy.PosTouchRatioX(it.position.x); float yZero = movementBloupy.PosTouchRatioX(pressPos.y); float yUn = movementBloupy.PosTouchRatioX(it.position.y); float deltaX = Math.Abs(xUn - xZero); float deltaY = Math.Abs(yUn - yZero); float swipe = (float)Math.Sqrt(deltaX * deltaX + deltaY * deltaY); if (swipe > movementBloupy.swipeAcceptance) { if (movementBloupy.GetSpeed() < movementBloupy.maxSpeed * superJumpSpeedCap) { movementBloupy.Jump(-1); } else { movementBloupy.SuperJump(-1); } } else //move left { movementBloupy.MoveLeft(); } /*------------------------------------------------------------------*/ break; case TouchPhase.Stationary: // Debug.Log("LEFT STATIONARY"); if (!movementBloupy.GetIsGrounded()) { if (movementBloupy.rb.velocity.y < 0) //BLOUPY IS FALLING { //if (transform.localScale.x < 0 && transform.position.x < movementBloupy.originalPos.x) //sprite to the left //{ // AIR CONTROL LEFT movementBloupy.Move(-Mathf.Abs(movementBloupy.aircontrol)); // } break; } } if (movementBloupy.GetIsPrepaNeutralJumping()) { break; } movementBloupy.MoveLeft(); break; case TouchPhase.Ended: // Debug.Log("LEFT ENDED"); releaseTime = Time.time; /* * if ( * rightTouch.currenttouch.phase == TouchPhase.Ended * && * Math.Abs(rightTouch.pressTime - rightTouch.releaseTime) >= movementBloupy.neutralJumpMinimumHolding * && * Math.Abs(pressTime - releaseTime) >= movementBloupy.neutralJumpMinimumHolding * && * Math.Abs(rightTouch.releaseTime - releaseTime) <= movementBloupy.doubleTapAcceptance * && * movementBloupy.GetIsPrepaNeutralJumping() * ) * { * //DOUBLE TAP RELEASE * Debug.Log("NeutralJumpLeft"); * movementBloupy.NeutralJump(); * return; * } * //movementBloupy.SetIsPrepaNeutralJumping(false); */ break; case TouchPhase.Canceled: // Debug.Log("LEFT CANCELED"); break; default: break; } break; } } } }