59 lines
1.7 KiB
C#
59 lines
1.7 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using BITKit;
|
|
using BITKit.Entities.Player;
|
|
using BITKit.SceneManagement;
|
|
using Cinemachine;
|
|
using Cysharp.Threading.Tasks;
|
|
using UnityEngine;
|
|
using YooAsset;
|
|
|
|
namespace BITFALL.GameMode
|
|
{
|
|
public class PlayerSpawnService : MonoBehaviour
|
|
{
|
|
[SerializeReference,SubclassSelector] private ISceneService sceneService;
|
|
[SerializeReference, SubclassSelector] private IReference playerPath;
|
|
[SerializeReference, SubclassSelector] private IPlayerService playerService;
|
|
[SerializeField] private CinemachineVirtualCamera virtualCamera;
|
|
|
|
private void Start()
|
|
{
|
|
virtualCamera.enabled = false;
|
|
sceneService.OnSceneLoaded += OnSceneLoaded;
|
|
destroyCancellationToken.Register(() =>
|
|
{
|
|
sceneService.OnSceneLoaded -= OnSceneLoaded;
|
|
});
|
|
}
|
|
|
|
private void OnSceneLoad(string obj)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
private async void OnSceneLoaded(string obj)
|
|
{
|
|
await UniTask.Delay(500);
|
|
var spawnPoint = NodeQuery.Query<InfoPlayerStart>().OrderBy(x => x.Property).First();
|
|
virtualCamera.transform.SetPositionAndRotation(spawnPoint.Position,spawnPoint.Rotation);
|
|
virtualCamera.enabled = true;
|
|
Camera.main.transform.position = spawnPoint.Position;
|
|
await UniTask.Delay(1000);
|
|
if (destroyCancellationToken.IsCancellationRequested) return;
|
|
|
|
if (playerService.LocalPlayer) return;
|
|
|
|
var player = YooAssets.LoadAssetAsync<GameObject>(playerPath.Value);
|
|
await player;
|
|
if (destroyCancellationToken.IsCancellationRequested) return;
|
|
|
|
var instance = Instantiate(player.AssetObject.As<GameObject>(),spawnPoint.Position, spawnPoint.Rotation);
|
|
virtualCamera.enabled = false;
|
|
}
|
|
}
|
|
}
|
|
|