73 lines
2.6 KiB
C#
73 lines
2.6 KiB
C#
using Cinemachine;
|
|
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
// ReSharper disable once CheckNamespace
|
|
namespace BlueWaterProject
|
|
{
|
|
public class SpawnController : MonoBehaviour
|
|
{
|
|
private GameObject spawnPositionObj;
|
|
private CinemachineVirtualCamera cinemachineVirtualCamera;
|
|
|
|
private const string PLAYER_NAME = "Player";
|
|
private const string IN_ISLAND_PLAYER_NAME = "InIslandPlayer";
|
|
|
|
private void Start()
|
|
{
|
|
spawnPositionObj = GameObject.Find("StageMap/SpawnPosition");
|
|
if (spawnPositionObj == null)
|
|
{
|
|
print("StageMap 또는 SpawnPosition 오브젝트를 찾을 수 없습니다.");
|
|
return;
|
|
}
|
|
|
|
cinemachineVirtualCamera = GameObject.Find("Virtual Camera")?.GetComponent<CinemachineVirtualCamera>();
|
|
if (cinemachineVirtualCamera == null)
|
|
{
|
|
print("Virtual Camera 오브젝트를 찾을 수 없습니다.");
|
|
return;
|
|
}
|
|
|
|
var currentSceneName = SceneManager.GetActiveScene().name;
|
|
if (currentSceneName != "02.Main")
|
|
{
|
|
SpawnInIslandPlayer(spawnPositionObj.transform.position, spawnPositionObj.transform.rotation);
|
|
}
|
|
}
|
|
|
|
private void SpawnInIslandPlayer(Vector3 spawnPos, Quaternion spawnRotation)
|
|
{
|
|
var islandPlayer = Instantiate(GameManager.Inst.inIslandPlayer, spawnPos, spawnRotation);
|
|
islandPlayer.name = IN_ISLAND_PLAYER_NAME;
|
|
|
|
var playerInput = islandPlayer.GetComponent<PlayerInput>();
|
|
if (playerInput == null)
|
|
{
|
|
playerInput = islandPlayer.AddComponent<PlayerInput>();
|
|
}
|
|
playerInput.actions = GameManager.Inst.playerAction;
|
|
|
|
var desiredActionMap = playerInput.actions.FindActionMap(PLAYER_NAME);
|
|
if (desiredActionMap == null)
|
|
{
|
|
print($"Action map named '{PLAYER_NAME}' not found in player actions!");
|
|
return;
|
|
}
|
|
|
|
playerInput.defaultActionMap = PLAYER_NAME;
|
|
|
|
if (GameManager.Inst.shipPlayer != null)
|
|
{
|
|
GameManager.Inst.shipPlayer.GetComponent<PlayerInput>().enabled = false;
|
|
}
|
|
playerInput.SwitchCurrentActionMap(PLAYER_NAME);
|
|
|
|
islandPlayer.AddComponent<InIslandPlayer>();
|
|
|
|
cinemachineVirtualCamera.Follow = islandPlayer.transform;
|
|
cinemachineVirtualCamera.LookAt = islandPlayer.transform;
|
|
}
|
|
}
|
|
} |