2023-11-15 23:54:54 +08:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using BITFALL.Scene;
|
|
|
|
using BITKit;
|
|
|
|
using BITKit.Entities;
|
2023-12-15 00:08:02 +08:00
|
|
|
using Cysharp.Threading.Tasks;
|
2023-11-15 23:54:54 +08:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace BITFALL.Entities.GameMode
|
|
|
|
{
|
|
|
|
public class EntitySpawnPoint : EntityBehavior
|
|
|
|
{
|
|
|
|
[SerializeReference, SubclassSelector, Inject]
|
|
|
|
private ISpawnPointService _spawnPointService;
|
|
|
|
|
|
|
|
[Inject] private IEntityMovement _movement;
|
2023-12-15 00:08:02 +08:00
|
|
|
public override async void OnStart()
|
2023-11-15 23:54:54 +08:00
|
|
|
{
|
|
|
|
base.OnStart();
|
|
|
|
try
|
2023-12-15 00:08:02 +08:00
|
|
|
{
|
|
|
|
await UniTask.NextFrame(destroyCancellationToken);
|
|
|
|
}
|
|
|
|
catch (OperationCanceledException)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-12-26 20:07:19 +08:00
|
|
|
if (Data.Get<int>(BITConstant.Environment.mp_respawn_on_death) is 0) return;
|
2023-12-15 00:08:02 +08:00
|
|
|
try
|
2023-11-15 23:54:54 +08:00
|
|
|
{
|
|
|
|
Matrix4x4 spawnPoint = _spawnPointService.RequestSpawnPoint();
|
2023-11-30 00:23:23 +08:00
|
|
|
|
2023-11-15 23:54:54 +08:00
|
|
|
_movement.Position = spawnPoint.GetPosition();
|
|
|
|
_movement.Rotation = spawnPoint.rotation;
|
2023-11-30 00:23:23 +08:00
|
|
|
|
2023-11-15 23:54:54 +08:00
|
|
|
}
|
|
|
|
catch (ArgumentOutOfRangeException)
|
|
|
|
{
|
2023-11-30 00:23:23 +08:00
|
|
|
|
2023-11-15 23:54:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|