|
|
|
|
|
|
[SerializeField] private Protagonist _playerPrefab = null; |
|
|
|
|
|
|
|
[Header("Scene References")] |
|
|
|
[SerializeField] private CameraManager _cameraManager; |
|
|
|
[SerializeField] private TransformEventChannelSO _frameObjectChannel; |
|
|
|
|
|
|
|
void Start() |
|
|
|
{ |
|
|
|
|
|
|
[ContextMenu("Attempt Auto Fill")] |
|
|
|
private void AutoFill() |
|
|
|
{ |
|
|
|
if (_cameraManager == null) |
|
|
|
_cameraManager = FindObjectOfType<CameraManager>(); |
|
|
|
|
|
|
|
if (_spawnLocations == null || _spawnLocations.Length == 0) |
|
|
|
_spawnLocations = transform.GetComponentsInChildren<Transform>(true) |
|
|
|
.Where(t => t != this.transform) |
|
|
|
|
|
|
private void Spawn(int spawnIndex) |
|
|
|
{ |
|
|
|
Transform spawnLocation = GetSpawnLocation(spawnIndex, _spawnLocations); |
|
|
|
Protagonist playerInstance = InstantiatePlayer(_playerPrefab, spawnLocation, _cameraManager); |
|
|
|
Protagonist playerInstance = InstantiatePlayer(_playerPrefab, spawnLocation); |
|
|
|
SetupCameras(playerInstance); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
return spawnLocations[index]; |
|
|
|
} |
|
|
|
|
|
|
|
private Protagonist InstantiatePlayer(Protagonist playerPrefab, Transform spawnLocation, CameraManager _cameraManager) |
|
|
|
private Protagonist InstantiatePlayer(Protagonist playerPrefab, Transform spawnLocation) |
|
|
|
{ |
|
|
|
if (playerPrefab == null) |
|
|
|
throw new Exception("Player Prefab can't be null."); |
|
|
|
|
|
|
|
|
|
|
private void SetupCameras(Protagonist player) |
|
|
|
{ |
|
|
|
player.gameplayCamera = _cameraManager.mainCamera.transform; |
|
|
|
_cameraManager.SetupProtagonistVirtualCamera(player.transform); |
|
|
|
//TODO: update this hacky assignment of mainCamera
|
|
|
|
player.gameplayCamera = UnityEngine.Object.FindObjectOfType<CameraManager>().mainCamera.transform; |
|
|
|
_frameObjectChannel.RaiseEvent(player.transform); |
|
|
|
} |
|
|
|
} |