这是第一个 Unity 开放项目的repo,是 Unity 和社区合作创建的一个小型开源游戏演示,第一款游戏是一款名为 Chop Chop 的动作冒险游戏。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

47 行
1.3 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LocalPoolTester : MonoBehaviour
{
[SerializeField]
private int _initialPoolSize = 5;
private ParticlePoolSO _pool;
private ParticleFactorySO _factory;
private void Awake()
{
DontDestroyOnLoad(this.gameObject);
}
private IEnumerator Start()
{
_factory = ScriptableObject.CreateInstance<ParticleFactorySO>();
_pool = ScriptableObject.CreateInstance<ParticlePoolSO>();
_pool.name = gameObject.name;
_pool.Factory = _factory;
_pool.SetParent(this.transform);
_pool.Prewarm(_initialPoolSize);
List<ParticleSystem> particles = _pool.Request(2) as List<ParticleSystem>;
foreach (ParticleSystem particle in particles)
{
StartCoroutine(DoParticleBehaviour(particle));
}
yield return new WaitForSeconds(2);
_pool.SetParent(null);
yield return new WaitForSeconds(2);
_pool.SetParent(this.transform);
}
private IEnumerator DoParticleBehaviour(ParticleSystem particle)
{
particle.transform.position = Random.insideUnitSphere * 5f;
particle.Play();
yield return new WaitForSeconds(particle.main.duration);
particle.Stop(true, ParticleSystemStopBehavior.StopEmitting);
yield return new WaitUntil(() => particle.particleCount == 0);
_pool.Return(particle);
}
}