private void TouchInputHandling(Touch touch) { if (touch.phase == TouchPhase.Began) { GameObject hitGO = PickObject(touch.position); OnPickUpObject?.Invoke(touch, hitGO); } if (touch.phase == TouchPhase.Canceled || touch.phase == TouchPhase.Ended) { GameObject hitGO = PickObject(touch.position); OnEndMovement?.Invoke(touch, hitGO); } }
private void GetInput() { int touchCount = Input.touchCount; if (oldTouchCount == 2 && touchCount <= 1) { OnEndDualSteering?.Invoke(); letGoOfDualSteering = true; } if (touchCount == 1) { Vector2 touchPos = Input.GetTouch(0).position; if (oldTouchCount == 0) { singleTouchBeginTime = Time.time; } float preRotInput; if (touchPos.x < GameManager.Instance.screenWidth * controlAreaSize / 2) { preRotInput = rotateSpeed; } else if (touchPos.x > GameManager.Instance.screenWidth - GameManager.Instance.screenWidth * controlAreaSize / 2) { preRotInput = -rotateSpeed; } else { touchCount = 0; preRotInput = 0; } preRotInput *= (Time.time - singleTouchBeginTime) * singleTouchAccelTime + 1; if (letGoOfDualSteering) { rotInput = Mathf.Lerp(rotInput, preRotInput, dualToSingleSlowdown * Time.deltaTime); } else { rotInput = preRotInput; } if (rotInput != 0 && oldTouchCount == 0) { OnBeginMovement?.Invoke(); } } else if (touchCount == 2) { if (oldTouchCount != 2) { if (oldTouchCount == 0) { OnBeginMovement?.Invoke(); } OnBeginDualSteering?.Invoke(); } Vector2[] touches = new Vector2[2]; for (int i = 0; i < 2; i++) { touches[i] = Input.GetTouch(i).position; } if (touches[0].x > touches[1].x) { Vector2 tmp = touches[0]; touches[0] = touches[1]; touches[1] = tmp; } if (touches[0].x <GameManager.Instance.screenWidth * controlAreaSize / 2 && touches[1].x> GameManager.Instance.screenWidth - GameManager.Instance.screenWidth * controlAreaSize / 2) { float deltaY = (touches[0].y - touches[1].y) / GameManager.Instance.screenHeight; float acceleration = deltaY - oldDeltaY; rotInput = -deltaY *deltaY *dualTouchRotateSpeed *Mathf.Sign(deltaY) - acceleration * accelFactor; oldDeltaY = deltaY; } else { if (touches[0].x < GameManager.Instance.screenWidth * controlAreaSize / 2) { rotInput = -rotateSpeed; } else if (touches[1].x > GameManager.Instance.screenWidth - GameManager.Instance.screenWidth * controlAreaSize / 2) { rotInput = rotateSpeed; } else { rotInput = 0; } } } else { rotInput = 0; letGoOfDualSteering = false; OnEndMovement?.Invoke(); } oldTouchCount = touchCount; }