1
This commit is contained in:
@@ -1,18 +1,61 @@
|
||||
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;
|
||||
|
||||
public class Prop_Flashbang : MonoBehaviour
|
||||
namespace BITFALL.Props
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
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();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user