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("Component")] private Rigidbody rb; private Vector2 movementInput; [Title("Child Object")] private GameObject character; [Title("쉽의 기본 설정")] [Tooltip("최대 스피드")] public float maxSpeed = 10f; [Tooltip("가속 수치")] public float acceleration = 2f; [Tooltip("감속 수치")] public float deceleration = 2f; [Tooltip("회전 속도")] public float turnSpeed = 10f; [Title("캐릭터의 기본 설정")] [Tooltip("캐릭터의 이동 속도")] public float characterSpeed = 10f; public bool IsAssaultMode { get; set; } public bool IsInShipMode { get; set; } public bool IsdredgeMode { get; set; } public bool IsTakeAim { get; set; } private void Init() { character = transform.Find("Character").gameObject; rb = GetComponent(); } #region Unity Function private void Awake() { Init(); } private void FixedUpdate() { if (IsInShipMode) { MoveCharacterPlayer(); } else { MoveShipPlayer(); RotatePlayer(); } } #endregion #region Movement public void OnMove(InputValue value) // WASD { movementInput = value.Get(); } private void MoveShipPlayer() { 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); } private void MoveCharacterPlayer() { Vector3 movement = character.transform.rotation * new Vector3(-movementInput.y, 0, movementInput.x) * (characterSpeed * Time.deltaTime); character.transform.position += movement; } #endregion #region AssaultMode/DreadgeMode Switch private void OnAssaultMode(InputValue value) // V { if (IsAssaultMode) { SwitchToDredgeMode(); } else { SwitchToAssaultMode(); } } private void SwitchToDredgeMode() { GameManager.Inst.CameraController.CamDredgeMode(); UiManager.Inst.CardLayoutGroupAnimator.Reverse(); IsAssaultMode = false; IsdredgeMode = true; } private void SwitchToAssaultMode() { GameManager.Inst.CameraController.CamAssaultMode(); UiManager.Inst.CardLayoutGroupAnimator.Play(); IsAssaultMode = true; IsdredgeMode = false; } #endregion #region Interaction Key private void OnInteraction(InputValue value) //F { } private void OnInteractionHold(InputValue value) //F Hold { if (IsInShipMode) { GameManager.Inst.CameraController.CamDredgeMode(); IsdredgeMode = true; IsAssaultMode = false; IsInShipMode = false; } else { GameManager.Inst.CameraController.CamInShipMode(); IsInShipMode = true; IsAssaultMode = false; IsdredgeMode = false; } } #endregion private void OnZkey(InputValue value) { UiManager.Inst.AddCard(); } private void OnTakeAim(InputValue value) // Space { IsTakeAim = !IsTakeAim; GameManager.Inst.CameraController.CamTakeAim(IsTakeAim); UiManager.Inst.AimOnOff(IsTakeAim); } } }