using Cinemachine; using Sirenix.OdinInspector; using UnityEngine; using UnityEngine.InputSystem; namespace _02.Scripts.WaterAndShip { [RequireComponent(typeof(Rigidbody))] [RequireComponent(typeof(PlayerInput))] public class Player : MonoBehaviour { [Title("쉽의 기본 설정")] [InfoBox("최대 스피드")] public float maxSpeed = 10f; [InfoBox("가속 수치")] public float acceleration = 2f; [InfoBox("감속 수치")] public float deceleration = 2f; [InfoBox("회전 속도")] public float turnSpeed = 10f; private Rigidbody rb; private Vector2 movementInput; public bool IsAssaultMode { get; set; } public bool IsInShipMode { get; set; } public bool IsdredgeMode { get; set; } private void Awake() { rb = GetComponent(); } private void FixedUpdate() { MovePlayer(); RotatePlayer(); } #region Movement public void OnMove(InputValue value) { movementInput = value.Get(); } private void MovePlayer() { var desiredVelocity = transform.forward * movementInput.y * maxSpeed; var speedChange = (movementInput.y != 0 ? acceleration : deceleration) * Time.fixedDeltaTime; rb.velocity = Vector3.MoveTowards(rb.velocity, desiredVelocity, speedChange); } private void RotatePlayer() { var turn = movementInput.x; var turnRotation = Quaternion.Euler(0f, turn * turnSpeed, 0f); rb.MoveRotation(rb.rotation * turnRotation); } #endregion #region AssaultMode/DreadgeMode Switch private void OnAssaultMode(InputValue value) { if (IsAssaultMode) { SwitchToDredgeMode(); } else { SwitchToAssaultMode(); } } private void SwitchToDredgeMode() { GameManager.Inst.CameraController.CamDredgeMode(); GameManager.Inst.UiController.uiAnimator.Reverse(); IsAssaultMode = false; IsdredgeMode = true; } private void SwitchToAssaultMode() { GameManager.Inst.CameraController.CamAssaultMode(); GameManager.Inst.UiController.uiAnimator.Play(); IsAssaultMode = true; IsdredgeMode = false; } #endregion #region Interaction Key private void OnInteraction(InputValue value) { } private void OnInteractionHold(InputValue value) { if (IsInShipMode) { GameManager.Inst.CameraController.CamDredgeMode(); IsdredgeMode = true; IsAssaultMode = false; IsInShipMode = false; } else { GameManager.Inst.CameraController.CamInShipMode(); IsInShipMode = true; IsAssaultMode = false; IsdredgeMode = false; } } #endregion } }