OldBlueWater/BlueWater/Assets/02.Scripts/GameManager.cs

170 lines
5.5 KiB
C#
Raw Normal View History

2023-08-08 07:08:41 +00:00
using System.Collections.Generic;
using BlueWaterProject;
2023-08-11 16:21:26 +00:00
using Sirenix.OdinInspector;
2023-08-08 07:08:41 +00:00
using UnityEngine;
2023-10-05 04:11:46 +00:00
using UnityEngine.InputSystem;
2023-08-08 07:08:41 +00:00
2023-08-31 06:46:13 +00:00
// ReSharper disable once CheckNamespace
namespace BlueWaterProject
2023-08-08 07:08:41 +00:00
{
2023-09-20 09:06:45 +00:00
[DefaultExecutionOrder(-1)]
2023-08-31 06:46:13 +00:00
public class GameManager : Singleton<GameManager>
{
[field: Title("Controller")]
2023-08-31 06:46:13 +00:00
public CameraController CameraController { get; private set; }
2023-09-27 02:55:13 +00:00
public ShipPlayer shipPlayer;
2023-10-06 05:41:16 +00:00
public List<Boat> boats = new(10);
2023-10-05 04:11:46 +00:00
[Required("BlueWater Player Input Action을 넣어주세요.")]
[field: SerializeField] public InputActionAsset PlayerAction { get; private set; }
2023-10-05 04:11:46 +00:00
[Required("Viking Prefab을 넣어주세요.")]
[field: SerializeField] public GameObject InIslandPlayer { get; private set; }
2023-08-11 16:21:26 +00:00
2023-08-31 06:46:13 +00:00
[Range(0f, 1f)]
[SerializeField] private float slowSpeed = 0.1f;
2023-10-05 04:11:46 +00:00
private const string IN_ISLAND_PLAYER_NAME = "InIslandPlayer";
2023-10-06 05:41:16 +00:00
[Title("Game State")]
[field: SerializeField] public bool IsInShipMode { get; set; }
[field: SerializeField] public bool IsDredgeMode { get; set; }
[field: SerializeField] public bool IsTakeAim { get; set; }
[field: SerializeField] public bool IsAssaultMode { get; set; }
[field: SerializeField] public GlobalValue.PlayerMode CurrentPlayerMode { get; set; }
2023-08-31 06:46:13 +00:00
private void Init()
{
CameraController = FindAnyObjectByType<CameraController>();
2023-09-27 02:55:13 +00:00
shipPlayer = FindAnyObjectByType<ShipPlayer>();
2023-08-31 06:46:13 +00:00
}
protected override void OnAwake()
{
Init();
}
2023-08-31 06:46:13 +00:00
private void Start()
{
Cursor.lockState = CursorLockMode.Confined;
}
2023-10-05 04:11:46 +00:00
public void SpawnInIslandPlayer(Vector3 spawnPosition)
{
var islandPlayer = Instantiate(InIslandPlayer, spawnPosition, Quaternion.identity);
2023-10-05 04:11:46 +00:00
islandPlayer.name = IN_ISLAND_PLAYER_NAME;
var playerInput = islandPlayer.GetComponent<PlayerInput>();
if (playerInput == null)
{
playerInput = islandPlayer.AddComponent<PlayerInput>();
}
playerInput.actions = PlayerAction;
2023-10-05 04:11:46 +00:00
var desiredActionMap = playerInput.actions.FindActionMap(IN_ISLAND_PLAYER_NAME);
if (desiredActionMap == null)
{
print($"Action map named '{IN_ISLAND_PLAYER_NAME}' not found in player actions!");
return;
}
playerInput.defaultActionMap = IN_ISLAND_PLAYER_NAME;
playerInput.SwitchCurrentActionMap(IN_ISLAND_PLAYER_NAME);
islandPlayer.AddComponent<InIslandPlayer>();
}
2023-10-06 05:41:16 +00:00
2023-08-31 06:46:13 +00:00
public void SlowSpeedMode()
{
Time.timeScale = slowSpeed;
Time.fixedDeltaTime = 0.02f * Time.timeScale;
}
2023-08-31 06:46:13 +00:00
public void DefaultSpeedMode()
{
Time.timeScale = 1f;
Time.fixedDeltaTime = 0.02f;
}
2023-10-06 05:41:16 +00:00
#region Player Mode State switch
2023-10-06 05:41:16 +00:00
public void SwitchDredgeMode(bool isOn)
{
if (isOn)
{
SwitchTakeAim(false);
SwitchAssaultMode(false);
SwitchInShipMode(false);
CameraController.CamDredgeMode();
IsDredgeMode = true;
CurrentPlayerMode = GlobalValue.PlayerMode.DREDGE;
2023-10-06 05:41:16 +00:00
}
else if (IsDredgeMode)
{
IsDredgeMode = false;
}
}
public void SwitchInShipMode(bool isOn)
{
if (isOn)
{
SwitchTakeAim(false);
SwitchAssaultMode(false);
SwitchDredgeMode(false);
CameraController.CamShipDeckMode();
2023-10-06 05:41:16 +00:00
IsInShipMode = true;
CurrentPlayerMode = GlobalValue.PlayerMode.IN_SHIP;
2023-10-06 05:41:16 +00:00
}
else if (IsInShipMode)
{
CameraController.CamDredgeMode();
IsInShipMode = false;
}
}
public void SwitchAssaultMode(bool isOn)
{
if (isOn)
{
SwitchTakeAim(false);
SwitchInShipMode(false);
SwitchDredgeMode(false);
CameraController.CamAssaultMode();
UiManager.Inst.CardLayoutGroupAnimator.Play();
IsAssaultMode = true;
CurrentPlayerMode = GlobalValue.PlayerMode.ASSAULT;
2023-10-06 05:41:16 +00:00
}
else if (IsAssaultMode)
{
CameraController.CamDredgeMode();
UiManager.Inst.CardLayoutGroupAnimator.Reverse();
IsAssaultMode = false;
}
}
public void SwitchTakeAim(bool isOn)
{
if (isOn)
{
SwitchAssaultMode(false);
SwitchInShipMode(false);
SwitchDredgeMode(false);
CameraController.CamTakeAim(true);
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
IsTakeAim = true;
CurrentPlayerMode = GlobalValue.PlayerMode.TAKE_AIM;
2023-10-06 05:41:16 +00:00
}
else if (IsTakeAim)
{
CameraController.CamTakeAim(false);
Cursor.visible = true;
Cursor.lockState = CursorLockMode.Confined;
IsTakeAim = false;
}
UiManager.Inst.AimOnOff(isOn);
}
#endregion
}
2023-08-08 07:08:41 +00:00
}