2023-09-11 01:55:36 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2023-08-31 06:46:13 +00:00
|
|
|
using Blobcreate.ProjectileToolkit;
|
2023-08-10 17:47:30 +00:00
|
|
|
using Sirenix.OdinInspector;
|
2023-08-03 01:03:08 +00:00
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.InputSystem;
|
|
|
|
|
2023-08-31 06:46:13 +00:00
|
|
|
// ReSharper disable once CheckNamespace
|
|
|
|
namespace BlueWaterProject
|
2023-08-03 01:03:08 +00:00
|
|
|
{
|
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-15 08:29:24 +00:00
|
|
|
[Title("Component")]
|
|
|
|
private Rigidbody rb;
|
|
|
|
private Vector2 movementInput;
|
|
|
|
|
2023-08-11 16:21:26 +00:00
|
|
|
[Title("쉽의 기본 설정")]
|
2023-08-15 08:29:24 +00:00
|
|
|
[Tooltip("최대 스피드")]
|
2023-08-03 02:54:21 +00:00
|
|
|
public float maxSpeed = 10f;
|
2023-08-15 08:29:24 +00:00
|
|
|
[Tooltip("가속 수치")]
|
2023-08-03 02:54:21 +00:00
|
|
|
public float acceleration = 2f;
|
2023-08-15 08:29:24 +00:00
|
|
|
[Tooltip("감속 수치")]
|
2023-08-03 02:54:21 +00:00
|
|
|
public float deceleration = 2f;
|
2023-08-15 08:29:24 +00:00
|
|
|
[Tooltip("회전 속도")]
|
2023-08-03 01:03:08 +00:00
|
|
|
public float turnSpeed = 10f;
|
2023-08-11 16:21:26 +00:00
|
|
|
|
2023-08-15 08:29:24 +00:00
|
|
|
[Title("캐릭터의 기본 설정")]
|
2023-09-11 01:55:36 +00:00
|
|
|
private GameObject character;
|
2023-08-15 08:29:24 +00:00
|
|
|
[Tooltip("캐릭터의 이동 속도")]
|
|
|
|
public float characterSpeed = 10f;
|
|
|
|
|
2023-08-31 06:46:13 +00:00
|
|
|
[Title("레이더")]
|
|
|
|
public Collider[] radar = new Collider[10];
|
|
|
|
public Transform[] inCameraRadar = new Transform[10];
|
|
|
|
public Transform target;
|
2023-09-11 05:15:18 +00:00
|
|
|
// 클래스 레벨 변수
|
|
|
|
private List<Transform> visibleObjects;
|
2023-08-31 06:46:13 +00:00
|
|
|
|
2023-09-11 01:55:36 +00:00
|
|
|
[Title("캐논")]
|
|
|
|
public Rigidbody projectilePrefab;
|
|
|
|
public Transform launchPoint;
|
|
|
|
public float timeOfFlight;
|
|
|
|
public Transform predictedPos;
|
|
|
|
public List<Canon> Canons { get; } = new (GlobalValue.MAX_CANON_COUNT);
|
|
|
|
|
2023-08-11 16:21:26 +00:00
|
|
|
public bool IsAssaultMode { get; set; }
|
|
|
|
public bool IsInShipMode { get; set; }
|
2023-08-29 04:23:27 +00:00
|
|
|
public bool IsDredgeMode { get; set; }
|
2023-08-22 05:31:24 +00:00
|
|
|
public bool IsTakeAim { get; set; }
|
2023-08-03 01:03:08 +00:00
|
|
|
|
2023-08-15 08:29:24 +00:00
|
|
|
private void Init()
|
2023-08-03 01:03:08 +00:00
|
|
|
{
|
2023-08-15 08:29:24 +00:00
|
|
|
character = transform.Find("Character").gameObject;
|
2023-08-03 01:03:08 +00:00
|
|
|
rb = GetComponent<Rigidbody>();
|
2023-09-11 05:15:18 +00:00
|
|
|
GetComponentsInChildren(Canons);
|
|
|
|
visibleObjects = new List<Transform>();
|
2023-08-03 01:03:08 +00:00
|
|
|
}
|
2023-08-15 08:29:24 +00:00
|
|
|
|
2023-08-17 03:42:12 +00:00
|
|
|
#region Unity Function
|
|
|
|
|
2023-08-15 08:29:24 +00:00
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
Init();
|
|
|
|
}
|
2023-09-11 01:55:36 +00:00
|
|
|
|
2023-09-11 05:15:18 +00:00
|
|
|
private void FixedUpdate()
|
2023-09-11 01:55:36 +00:00
|
|
|
{
|
2023-09-11 05:15:18 +00:00
|
|
|
HandleMovement();
|
2023-09-11 01:55:36 +00:00
|
|
|
}
|
|
|
|
|
2023-09-11 05:15:18 +00:00
|
|
|
private void Update()
|
2023-08-08 07:08:41 +00:00
|
|
|
{
|
2023-09-11 05:15:18 +00:00
|
|
|
FindInRadarRange();
|
|
|
|
FilterInCameraObjects();
|
|
|
|
FindTarget();
|
|
|
|
LookAtTarget();
|
2023-08-08 07:08:41 +00:00
|
|
|
}
|
2023-08-17 03:42:12 +00:00
|
|
|
|
|
|
|
#endregion
|
2023-08-11 16:21:26 +00:00
|
|
|
|
|
|
|
#region Movement
|
|
|
|
|
2023-08-23 07:32:24 +00:00
|
|
|
public void OnMove(InputValue value) // WASD
|
2023-08-11 16:21:26 +00:00
|
|
|
{
|
|
|
|
movementInput = value.Get<Vector2>();
|
|
|
|
}
|
|
|
|
|
2023-08-15 08:29:24 +00:00
|
|
|
private void MoveShipPlayer()
|
2023-08-11 16:21:26 +00:00
|
|
|
{
|
2023-08-16 01:38:47 +00:00
|
|
|
var desiredVelocity = transform.forward * (movementInput.y * maxSpeed);
|
2023-08-11 16:21:26 +00:00
|
|
|
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);
|
|
|
|
}
|
2023-08-15 08:29:24 +00:00
|
|
|
|
|
|
|
private void MoveCharacterPlayer()
|
|
|
|
{
|
2023-08-16 01:38:47 +00:00
|
|
|
Vector3 movement = character.transform.rotation * new Vector3(-movementInput.y, 0, movementInput.x) * (characterSpeed * Time.deltaTime);
|
2023-08-15 08:29:24 +00:00
|
|
|
|
|
|
|
character.transform.position += movement;
|
|
|
|
}
|
2023-08-11 16:21:26 +00:00
|
|
|
|
2023-09-11 05:15:18 +00:00
|
|
|
private void HandleMovement()
|
|
|
|
{
|
|
|
|
if (IsInShipMode)
|
|
|
|
{
|
|
|
|
MoveCharacterPlayer();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MoveShipPlayer();
|
|
|
|
RotatePlayer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-11 16:21:26 +00:00
|
|
|
#endregion
|
|
|
|
|
2023-08-08 07:08:41 +00:00
|
|
|
#region AssaultMode/DreadgeMode Switch
|
|
|
|
|
2023-08-23 07:32:24 +00:00
|
|
|
private void OnAssaultMode(InputValue value) // V
|
2023-08-08 07:08:41 +00:00
|
|
|
{
|
2023-08-29 04:23:27 +00:00
|
|
|
SwitchAssaultMode(!IsAssaultMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void SwitchAssaultMode(bool isOn)
|
|
|
|
{
|
|
|
|
if (isOn)
|
2023-08-08 07:08:41 +00:00
|
|
|
{
|
2023-08-29 04:23:27 +00:00
|
|
|
SwitchTakeAim(false);
|
|
|
|
SwitchInShipMode(false);
|
|
|
|
GameManager.Inst.CameraController.CamAssaultMode();
|
|
|
|
UiManager.Inst.CardLayoutGroupAnimator.Play();
|
|
|
|
IsAssaultMode = true;
|
2023-08-08 07:08:41 +00:00
|
|
|
}
|
2023-08-29 04:23:27 +00:00
|
|
|
else if (IsAssaultMode)
|
2023-08-08 07:08:41 +00:00
|
|
|
{
|
2023-08-29 04:23:27 +00:00
|
|
|
GameManager.Inst.CameraController.CamDredgeMode();
|
|
|
|
UiManager.Inst.CardLayoutGroupAnimator.Reverse();
|
|
|
|
IsAssaultMode = false;
|
2023-08-08 07:08:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2023-08-11 16:21:26 +00:00
|
|
|
#region Interaction Key
|
|
|
|
|
2023-09-11 05:15:18 +00:00
|
|
|
private void OnInteractionE(InputValue value) //E
|
2023-09-04 03:20:01 +00:00
|
|
|
{
|
2023-09-11 01:55:36 +00:00
|
|
|
UiManager.Inst.CheckRadarOverlap();
|
2023-09-04 03:20:01 +00:00
|
|
|
}
|
|
|
|
|
2023-08-23 07:32:24 +00:00
|
|
|
private void OnInteraction(InputValue value) //F
|
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-23 07:32:24 +00:00
|
|
|
private void OnInteractionHold(InputValue value) //F Hold
|
2023-08-03 01:03:08 +00:00
|
|
|
{
|
2023-08-29 04:23:27 +00:00
|
|
|
SwitchInShipMode(!IsInShipMode);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void SwitchInShipMode(bool isOn)
|
|
|
|
{
|
|
|
|
if (isOn)
|
2023-08-11 16:21:26 +00:00
|
|
|
{
|
2023-08-29 04:23:27 +00:00
|
|
|
SwitchTakeAim(false);
|
|
|
|
SwitchAssaultMode(false);
|
2023-08-11 16:21:26 +00:00
|
|
|
GameManager.Inst.CameraController.CamInShipMode();
|
|
|
|
IsInShipMode = true;
|
2023-08-29 04:23:27 +00:00
|
|
|
}
|
|
|
|
else if (IsInShipMode)
|
|
|
|
{
|
|
|
|
GameManager.Inst.CameraController.CamDredgeMode();
|
|
|
|
IsInShipMode = false;
|
2023-08-11 16:21:26 +00:00
|
|
|
}
|
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-17 03:42:12 +00:00
|
|
|
|
|
|
|
private void OnZkey(InputValue value)
|
|
|
|
{
|
|
|
|
UiManager.Inst.AddCard();
|
|
|
|
}
|
2023-09-11 01:55:36 +00:00
|
|
|
|
2023-09-11 05:15:18 +00:00
|
|
|
#region TakeAim
|
2023-09-11 01:55:36 +00:00
|
|
|
|
2023-08-23 07:32:24 +00:00
|
|
|
private void OnTakeAim(InputValue value) // Space
|
2023-08-22 05:31:24 +00:00
|
|
|
{
|
2023-08-29 04:23:27 +00:00
|
|
|
SwitchTakeAim(!IsTakeAim);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void SwitchTakeAim(bool isOn)
|
|
|
|
{
|
|
|
|
if (isOn)
|
|
|
|
{
|
|
|
|
SwitchAssaultMode(false);
|
|
|
|
SwitchInShipMode(false);
|
|
|
|
GameManager.Inst.CameraController.CamTakeAim(true);
|
|
|
|
Cursor.visible = false;
|
|
|
|
Cursor.lockState = CursorLockMode.Locked;
|
|
|
|
IsTakeAim = true;
|
|
|
|
}
|
|
|
|
else if (IsTakeAim)
|
|
|
|
{
|
|
|
|
GameManager.Inst.CameraController.CamTakeAim(false);
|
|
|
|
Cursor.visible = true;
|
|
|
|
Cursor.lockState = CursorLockMode.Confined;
|
|
|
|
IsTakeAim = false;
|
|
|
|
}
|
|
|
|
UiManager.Inst.AimOnOff(isOn);
|
2023-08-22 05:31:24 +00:00
|
|
|
}
|
2023-08-30 05:17:26 +00:00
|
|
|
|
2023-09-11 01:55:36 +00:00
|
|
|
#endregion
|
|
|
|
|
2023-09-11 05:15:18 +00:00
|
|
|
#region CanonAndRader
|
|
|
|
|
|
|
|
private void FindInRadarRange()
|
2023-08-30 05:17:26 +00:00
|
|
|
{
|
2023-09-11 05:15:18 +00:00
|
|
|
Physics.OverlapSphereNonAlloc(transform.position, GlobalValue.RADAR_RANGE, radar, LayerMask.GetMask(GlobalValue.ENEMY_LAYER));
|
|
|
|
}
|
|
|
|
|
|
|
|
private void FilterInCameraObjects()
|
|
|
|
{
|
|
|
|
visibleObjects.Clear();
|
|
|
|
foreach (var col in radar)
|
|
|
|
{
|
|
|
|
if (col == null) continue;
|
|
|
|
var screenPoint = Camera.main.WorldToViewportPoint(col.transform.position);
|
|
|
|
if (screenPoint.z > 0 && screenPoint.x >= 0 && screenPoint.x <= 1 && screenPoint.y >= 0 && screenPoint.y <= 1)
|
|
|
|
{
|
|
|
|
visibleObjects.Add(col.transform);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
visibleObjects.Sort((a, b) => Vector3.Distance(transform.position, a.position).CompareTo(Vector3.Distance(transform.position, b.position)));
|
|
|
|
}
|
|
|
|
|
|
|
|
private void FindTarget()
|
|
|
|
{
|
|
|
|
foreach (var trans in visibleObjects)
|
|
|
|
{
|
|
|
|
if (trans.Find("TestTarget") == null) continue;
|
|
|
|
target = trans.Find("TestTarget").transform;
|
|
|
|
break;
|
|
|
|
}
|
2023-08-30 05:17:26 +00:00
|
|
|
}
|
2023-09-11 05:15:18 +00:00
|
|
|
|
|
|
|
private void LookAtTarget()
|
|
|
|
{
|
|
|
|
if (target == null) return;
|
|
|
|
foreach (var canon in Canons)
|
|
|
|
{
|
|
|
|
canon.predictedPos = target;
|
|
|
|
canon.LookAtTarget();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
2023-08-03 01:03:08 +00:00
|
|
|
}
|
2023-08-03 02:54:21 +00:00
|
|
|
}
|