/// <summary> /// Move to first person mode. /// </summary> /// <param name="shooter"></param> public void TransitionToFirstPerson(Shooter shooter) { // Already in this state, return. if (m_currentMode == CameraMode.FirstPerson) { return; } // Get the destination m_lastOrthoPosition = transform.position; m_lastOrthoRotation = transform.rotation; m_desiredPosition = shooter.CameraSocket.position; m_desiredRotation = shooter.CameraSocket.rotation; // Toggle it to Perspective GetComponent <MatrixBlender>().BlendToMatrix(m_perspective, CameraLerpTime, MatrixLerpEase, false); //GetComponent<Camera>().projectionMatrix = Matrix4x4.Perspective(FOV, 16f/9f, zNear, zFar); // Hide the 3rd person canvas. GameManager.Instance.GameCanvas.ThirdPersonTutorial.gameObject.SetActive(false); // Change the state machine state m_currentMode = CameraMode.FirstPerson; m_firstPersonState = new GameCameraFirstPersonState(); m_firstPersonState.SetShooter(shooter); m_stateMachine.ChangeState(m_firstPersonState); // Move the camera StartCoroutine(LerpCameraToRotation(() => { // Show the First Person Canvas. GameManager.Instance.GameCanvas.FirstPersonCanvas.gameObject.SetActive(true); })); }
/// <summary> /// Start /// </summary> void Start() { m_aspectRatio = (float)Screen.width / (float)Screen.height; //ortho = Matrix4x4.Ortho(-orthographicSize * aspect, orthographicSize * aspect, -orthographicSize, orthographicSize, near, far); m_perspective = Matrix4x4.Perspective(FOV, m_aspectRatio, zNear, zFar); // Ortho hack. Math is hard. m_startingOrthoProjectionMatrix = GetComponent <Camera>().projectionMatrix; // Make the states m_firstPersonState = new GameCameraFirstPersonState(); m_thirdPersonState = new GameCameraThirdPersonState(); m_stateMachine = new FiniteStateMachine(m_thirdPersonState, this); }