BITKit/Packages/Runtime~/Unity/Scripts/Components/EffectPlayer.cs

40 lines
1.1 KiB
C#
Raw Normal View History

2023-06-05 19:57:17 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cysharp.Threading.Tasks;
namespace BITKit
{
public class EffectPlayer : MonoBehaviour
{
[Header(Constant.Header.Settings)]
[SerializeField] float duration;
[Header(Constant.Header.Components)]
[SerializeField] ParticleSystem[] particleSystems;
[SerializeField] Behaviour[] behaviours;
void Start()
{
particleSystems.ForEach(x => x.Stop());
behaviours.ForEach(x => x.enabled = false);
}
public async void Excute()
{
particleSystems.ForEach(x =>
{
x.time = 0;
x.Play(true);
});
behaviours.ForEach(x =>
{
x.enabled = true;
});
await UniTask.Delay(System.TimeSpan.FromSeconds(duration));
if (BehaviourHelper.Actived)
{
behaviours.ForEach(x =>
{
x.enabled = false;
});
}
}
}
}