62 lines
1.7 KiB
C#
62 lines
1.7 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using BITKit;
|
|
using BITKit.Entities;
|
|
using BITKit.Sensors;
|
|
using BITKit.Tween;
|
|
using Cysharp.Threading.Tasks;
|
|
using UnityEngine;
|
|
|
|
namespace BITFALL.Props
|
|
{
|
|
public class Prop_Flashbang : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private float fuse;
|
|
|
|
[SerializeField] private float duration = 5;
|
|
[SerializeField] private Light light;
|
|
[SerializeReference,SubclassSelector] private ISensor _sensor;
|
|
|
|
private async void Start()
|
|
{
|
|
await UniTask.Delay(TimeSpan.FromSeconds(fuse));
|
|
if (destroyCancellationToken.IsCancellationRequested) return;
|
|
await _sensor.Execute(0);
|
|
if (destroyCancellationToken.IsCancellationRequested) return;
|
|
foreach (var x in _sensor.Get())
|
|
{
|
|
if (x.TryGetComponent<IEntity>(out var entity) is false) continue;
|
|
if (entity.TryGetComponent<IStunObject>(out var stunObject) is false) continue;
|
|
var distance = Vector3.Distance(transform.position, x.transform.position);
|
|
stunObject.Stun(distance, duration);
|
|
BIT4Log.Log<Prop_Flashbang>($"目标:{x.name} 距离:{distance} 眩晕时间:{duration}");
|
|
}
|
|
|
|
light.enabled = true;
|
|
var currentIntensity = light.intensity;
|
|
await BITween.CreateSequence()
|
|
.Append(
|
|
BITween.MoveToForward(Set, currentIntensity, 0, 0.2f)
|
|
)
|
|
//.Append(UniTask.Create(Dispose))
|
|
.Play();
|
|
if(destroyCancellationToken.IsCancellationRequested) return;
|
|
Destroy(gameObject);
|
|
}
|
|
private UniTask Dispose()
|
|
{
|
|
if (destroyCancellationToken.IsCancellationRequested) return UniTask.CompletedTask;
|
|
Destroy(gameObject);
|
|
return UniTask.CompletedTask;;
|
|
}
|
|
private void Set(float weight)
|
|
{
|
|
if (light)
|
|
light.intensity = weight;
|
|
}
|
|
}
|
|
|
|
}
|