1
This commit is contained in:
49
Assets/Artists/Scripts/GameMode/PlayerAutoSpawnController.cs
Normal file
49
Assets/Artists/Scripts/GameMode/PlayerAutoSpawnController.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using BITKit;
|
||||
using BITKit.Entities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITFALL.GameMode
|
||||
{
|
||||
public class PlayerAutoSpawnController : MonoBehaviour
|
||||
{
|
||||
[SerializeReference, SubclassSelector] private IEntitiesService entitiesService;
|
||||
private void Start()
|
||||
{
|
||||
entitiesService.OnAdd += OnEntityAdded;
|
||||
destroyCancellationToken.Register(() =>
|
||||
{
|
||||
entitiesService.OnAdd -= OnEntityAdded;
|
||||
});
|
||||
}
|
||||
private void OnEntityAdded(IEntity obj)
|
||||
{
|
||||
if (obj.TryGetComponent<IHealth>(out var heal) is false) return;
|
||||
var token = destroyCancellationToken;
|
||||
if (obj is MonoBehaviour behaviour)
|
||||
{
|
||||
token = behaviour.destroyCancellationToken;
|
||||
}
|
||||
heal.OnSetAlive +=async alive =>
|
||||
{
|
||||
if(alive)return;
|
||||
var time = Data.Get<int>(BITConstant.Environment.mp_respawn_on_death);
|
||||
switch (time)
|
||||
{
|
||||
case 0:
|
||||
heal.HealthPoint = heal.MaxHealthPoint;
|
||||
return;
|
||||
case -1:
|
||||
return;
|
||||
default:
|
||||
await Task.Delay(TimeSpan.FromSeconds(time),token);
|
||||
heal.HealthPoint = heal.MaxHealthPoint;
|
||||
break;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user