46 lines
1.3 KiB
C#
46 lines
1.3 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using BITKit;
|
|
using BITKit.Entities.Player;
|
|
using BITKit.SceneManagement;
|
|
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;
|
|
private void Start()
|
|
{
|
|
sceneService.OnSceneLoaded += OnSceneLoaded;
|
|
destroyCancellationToken.Register(() =>
|
|
{
|
|
sceneService.OnSceneLoaded -= OnSceneLoaded;
|
|
});
|
|
}
|
|
|
|
private async void OnSceneLoaded(string obj)
|
|
{
|
|
await UniTask.Delay(100);
|
|
if (destroyCancellationToken.IsCancellationRequested) return;
|
|
|
|
if (playerService.LocalPlayer) return;
|
|
|
|
var player = YooAssets.LoadAssetAsync<GameObject>(playerPath.Value);
|
|
await player;
|
|
if (destroyCancellationToken.IsCancellationRequested) return;
|
|
|
|
var spawnPoint = NodeQuery.Query<InfoPlayerStart>().OrderBy(x => x.Property).First();
|
|
|
|
var instance = Instantiate(player.AssetObject.As<GameObject>(),spawnPoint.Position, spawnPoint.Rotation);
|
|
}
|
|
}
|
|
}
|
|
|