OldBlueWater/BlueWater/Assets/02.Scripts/WaterAndShip/Player.cs

121 lines
3.3 KiB
C#
Raw Normal View History

2023-08-08 07:08:41 +00:00
using Cinemachine;
using Sirenix.OdinInspector;
2023-08-03 01:03:08 +00:00
using UnityEngine;
using UnityEngine.InputSystem;
namespace _02.Scripts.WaterAndShip
{
2023-08-10 13:33:10 +00:00
[RequireComponent(typeof(Rigidbody))]
[RequireComponent(typeof(PlayerInput))]
2023-08-03 01:03:08 +00:00
public class Player : MonoBehaviour
{
2023-08-11 16:21:26 +00:00
[Title("쉽의 기본 설정")]
[InfoBox("최대 스피드")]
2023-08-03 02:54:21 +00:00
public float maxSpeed = 10f;
[InfoBox("가속 수치")]
2023-08-03 02:54:21 +00:00
public float acceleration = 2f;
[InfoBox("감속 수치")]
2023-08-03 02:54:21 +00:00
public float deceleration = 2f;
[InfoBox("회전 속도")]
2023-08-03 01:03:08 +00:00
public float turnSpeed = 10f;
2023-08-11 16:21:26 +00:00
2023-08-03 01:03:08 +00:00
private Rigidbody rb;
private Vector2 movementInput;
2023-08-11 16:21:26 +00:00
public bool IsAssaultMode { get; set; }
public bool IsInShipMode { get; set; }
public bool IsdredgeMode { get; set; }
2023-08-03 01:03:08 +00:00
2023-08-04 16:02:49 +00:00
private void Awake()
2023-08-03 01:03:08 +00:00
{
rb = GetComponent<Rigidbody>();
}
2023-08-08 07:08:41 +00:00
private void FixedUpdate()
{
MovePlayer();
RotatePlayer();
}
2023-08-11 16:21:26 +00:00
#region Movement
public void OnMove(InputValue value)
{
movementInput = value.Get<Vector2>();
}
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);
}
2023-08-08 07:08:41 +00:00
2023-08-11 16:21:26 +00:00
private void RotatePlayer()
{
var turn = movementInput.x;
var turnRotation = Quaternion.Euler(0f, turn * turnSpeed, 0f);
rb.MoveRotation(rb.rotation * turnRotation);
}
#endregion
2023-08-08 07:08:41 +00:00
#region AssaultMode/DreadgeMode Switch
2023-08-11 16:21:26 +00:00
private void OnAssaultMode(InputValue value)
2023-08-08 07:08:41 +00:00
{
2023-08-11 16:21:26 +00:00
if (IsAssaultMode)
2023-08-08 07:08:41 +00:00
{
SwitchToDredgeMode();
}
else
{
SwitchToAssaultMode();
}
}
private void SwitchToDredgeMode()
{
GameManager.Inst.CameraController.CamDredgeMode();
2023-08-08 16:58:35 +00:00
GameManager.Inst.UiController.uiAnimator.Reverse();
2023-08-11 16:21:26 +00:00
IsAssaultMode = false;
IsdredgeMode = true;
2023-08-08 07:08:41 +00:00
}
2023-08-03 01:03:08 +00:00
2023-08-08 07:08:41 +00:00
private void SwitchToAssaultMode()
{
GameManager.Inst.CameraController.CamAssaultMode();
2023-08-08 16:58:35 +00:00
GameManager.Inst.UiController.uiAnimator.Play();
2023-08-11 16:21:26 +00:00
IsAssaultMode = true;
IsdredgeMode = false;
2023-08-08 07:08:41 +00:00
}
#endregion
2023-08-11 16:21:26 +00:00
#region Interaction Key
private void OnInteraction(InputValue value)
2023-08-03 01:03:08 +00:00
{
2023-08-11 16:21:26 +00:00
2023-08-03 01:03:08 +00:00
}
2023-08-08 07:08:41 +00:00
2023-08-11 16:21:26 +00:00
private void OnInteractionHold(InputValue value)
2023-08-03 01:03:08 +00:00
{
2023-08-11 16:21:26 +00:00
if (IsInShipMode)
{
GameManager.Inst.CameraController.CamDredgeMode();
IsdredgeMode = true;
IsAssaultMode = false;
IsInShipMode = false;
}
else
{
GameManager.Inst.CameraController.CamInShipMode();
IsInShipMode = true;
IsAssaultMode = false;
IsdredgeMode = false;
}
2023-08-08 07:08:41 +00:00
}
2023-08-03 01:03:08 +00:00
2023-08-08 07:08:41 +00:00
#endregion
2023-08-03 01:03:08 +00:00
}
2023-08-03 02:54:21 +00:00
}