OldBlueWater/BlueWater/Assets/02.Scripts/GameManager.cs
NTG 59c4b14d1a #34 #35 InIslandPlayer, Ai 2D 베이스 변경 작업
+ SPUM 프리팹 NavMeshAgent 위치 변경, 콜라이더, Agent 크기 변경
+ SPUM에서 제공되는 NormalAnimator의 공격 모션에 Event 추가
+ Ork 프리팹 UnitRoot에 Animator Bridge 추가
+ IAiView 타겟을 검색하는 Ai 인터페이스 추가
+ IHelpCall 주변 아군에게 타겟을 공유하는 인터페이스 추가
+ 기존 02.Scripts.Ai.BehaviorTree에는 그대로 냅두고,
  02.Scripts.Ai.NewBehaviorTree 폴더를 추가하여 사용
+ Enemy의 BehaviorTree인 Minion 추가
+ InIslandPlayer의 기본 이동 구현
2023-10-12 05:26:45 +09:00

165 lines
5.1 KiB
C#

using System.Collections.Generic;
using BlueWaterProject;
using Sirenix.OdinInspector;
using UnityEngine;
using UnityEngine.InputSystem;
// ReSharper disable once CheckNamespace
namespace BlueWaterProject
{
[DefaultExecutionOrder(-1)]
public class GameManager : Singleton<GameManager>
{
[field: Title("Controller")]
public CameraController CameraController { get; private set; }
public ShipPlayer shipPlayer;
public List<Boat> boats = new(10);
[Required("BlueWater Player Input Action을 넣어주세요.")]
[field: SerializeField] public InputActionAsset PlayerAction { get; private set; }
[Required("Viking Prefab을 넣어주세요.")]
[field: SerializeField] public GameObject InIslandPlayer { get; private set; }
[Range(0f, 1f)]
[SerializeField] private float slowSpeed = 0.1f;
private const string IN_ISLAND_PLAYER_NAME = "InIslandPlayer";
[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; }
private void Init()
{
CameraController = FindAnyObjectByType<CameraController>();
shipPlayer = FindAnyObjectByType<ShipPlayer>();
}
protected override void OnAwake()
{
Init();
}
private void Start()
{
Cursor.lockState = CursorLockMode.Confined;
}
public void SpawnInIslandPlayer(Vector3 spawnPosition)
{
var islandPlayer = Instantiate(InIslandPlayer, spawnPosition, Quaternion.identity);
islandPlayer.name = IN_ISLAND_PLAYER_NAME;
var playerInput = islandPlayer.GetComponent<PlayerInput>();
if (playerInput == null)
{
playerInput = islandPlayer.AddComponent<PlayerInput>();
}
playerInput.actions = PlayerAction;
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>();
}
public void SlowSpeedMode()
{
Time.timeScale = slowSpeed;
Time.fixedDeltaTime = 0.02f * Time.timeScale;
}
public void DefaultSpeedMode()
{
Time.timeScale = 1f;
Time.fixedDeltaTime = 0.02f;
}
#region Game State switch
public void SwitchDredgeMode(bool isOn)
{
if (isOn)
{
SwitchTakeAim(false);
SwitchAssaultMode(false);
SwitchInShipMode(false);
CameraController.CamDredgeMode();
IsDredgeMode = true;
}
else if (IsDredgeMode)
{
IsDredgeMode = false;
}
}
public void SwitchInShipMode(bool isOn)
{
if (isOn)
{
SwitchTakeAim(false);
SwitchAssaultMode(false);
SwitchDredgeMode(false);
CameraController.CamInShipMode();
IsInShipMode = true;
}
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;
}
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;
}
else if (IsTakeAim)
{
CameraController.CamTakeAim(false);
Cursor.visible = true;
Cursor.lockState = CursorLockMode.Confined;
IsTakeAim = false;
}
UiManager.Inst.AimOnOff(isOn);
}
#endregion
}
}