OldBlueWater/BlueWater/Assets/02.Scripts/GameManager.cs
2023-10-05 13:11:46 +09:00

85 lines
2.6 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>
{
[Title("Controller")]
public CameraController CameraController { get; private set; }
public ShipPlayer shipPlayer;
public List<Boat> boats = new List<Boat>(10);
[Required("BlueWater Player Input Action을 넣어주세요.")]
[SerializeField] private InputActionAsset playerAction;
[Required("Viking Prefab을 넣어주세요.")]
[SerializeField] private GameObject inIslandPlayer;
[Range(0f, 1f)]
[SerializeField] private float slowSpeed = 0.1f;
private const string IN_ISLAND_PLAYER_NAME = "InIslandPlayer";
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 testPrint()
{
print("Boat가 목표에 도착해서 이 함수를 호출합니다");
}
public void SlowSpeedMode()
{
Time.timeScale = slowSpeed;
Time.fixedDeltaTime = 0.02f * Time.timeScale;
}
public void DefaultSpeedMode()
{
Time.timeScale = 1f;
Time.fixedDeltaTime = 0.02f;
}
}
}