您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
37 行
779 B
37 行
779 B
using UOP1.Pool;
|
|
using System;
|
|
using System.Collections;
|
|
using UnityEngine;
|
|
|
|
public class PoolableParticle : MonoBehaviour, IPoolable
|
|
{
|
|
[SerializeField]
|
|
private ParticleSystem _particleSystem = default;
|
|
|
|
public void OnRequest()
|
|
{
|
|
gameObject.SetActive(true);
|
|
}
|
|
|
|
public void Play()
|
|
{
|
|
_particleSystem.Play();
|
|
}
|
|
|
|
public void OnReturn(Action onReturned)
|
|
{
|
|
StartCoroutine(DoReturn(onReturned));
|
|
}
|
|
|
|
IEnumerator DoReturn(Action onReturned)
|
|
{
|
|
if (_particleSystem.isPlaying)
|
|
{
|
|
yield return new WaitForSeconds(_particleSystem.main.duration - (_particleSystem.time % _particleSystem.main.duration));
|
|
_particleSystem.Stop();
|
|
}
|
|
yield return new WaitUntil(() => _particleSystem.particleCount == 0);
|
|
onReturned.Invoke();
|
|
gameObject.SetActive(false);
|
|
}
|
|
}
|