You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.4 KiB
55 lines
1.4 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class ParticlePool : MonoBehaviour
|
|
{
|
|
|
|
[AutoUI][Range(0,5)] public int GroupCount;
|
|
[AutoUI][Range(0, 10)] public int ParticleAmount = 1;
|
|
public List<ParticleSystem> ParticleGroups = new List<ParticleSystem>();
|
|
|
|
private const int total = 5;
|
|
|
|
private void Start()
|
|
{
|
|
for(int i = 0;i<transform.childCount;i++)
|
|
{
|
|
var particle = transform.GetChild(i).GetComponent<ParticleSystem>();
|
|
Put(particle);
|
|
}
|
|
}
|
|
|
|
public bool Take(out ParticleSystem paritcle)
|
|
{
|
|
var count = transform.childCount - GroupCount;
|
|
if (ParticleGroups.Count > count)
|
|
{
|
|
paritcle = ParticleGroups[Random.Range(0, ParticleGroups.Count)];
|
|
OpenParticle(paritcle);
|
|
return true;
|
|
}
|
|
paritcle = null;
|
|
return false;
|
|
}
|
|
|
|
public void Put(ParticleSystem paritcle)
|
|
{
|
|
paritcle.transform.parent = transform;
|
|
ParticleGroups.Add(paritcle);
|
|
CloseParticle(paritcle);
|
|
}
|
|
|
|
public void CloseParticle(ParticleSystem paritcle)
|
|
{
|
|
var emission = paritcle.emission;
|
|
emission.rateOverDistance = 0;
|
|
}
|
|
|
|
public void OpenParticle(ParticleSystem paritcle)
|
|
{
|
|
var emission = paritcle.emission;
|
|
emission.rateOverDistance = 1;
|
|
}
|
|
|
|
}
|
|
|