1 #region Copyright Notice & License Information
29 using System.Collections;
40 [AddComponentMenu (
"Hydrogen/Object Pool Item")]
56 StartCoroutine (WaitForParticles ());
68 return ParentPool.HasRigidbody && gameObject.rigidbody.IsSleeping ();
79 gameObject.rigidbody.velocity = Vector3.zero;
82 gameObject.SetActive (
false);
92 gameObject.SetActive (
true);
96 StartCoroutine (DespawnTimer ());
102 IEnumerator DespawnTimer ()
104 yield
return new WaitForSeconds (
LifeTime);
105 hObjectPool.Instance.Despawn (gameObject, PoolID);
111 IEnumerator WaitForParticles ()
113 if (particleEmitter != null) {
115 yield
return new WaitForEndOfFrame ();
117 while (particleEmitter.particleCount > 0) {
120 particleEmitter.emit =
false;
121 }
else if (particleSystem != null) {
122 yield
return new WaitForSeconds (particleSystem.startDelay + 0.25f);
123 while (particleSystem.IsAlive (
true)) {
124 if (!particleSystem.gameObject.activeSelf) {
125 particleSystem.Clear (
true);
133 gameObject.SetActive (
false);
136 hObjectPool.Instance.ObjectPools [PoolID].DespawnImmediate (gameObject);
float LifeTime
Despawn gameObject after this number of seconds.
override void DespawnSafely()
Despawn the gameObject safely after all particles have done their thing.
override bool IsInactive()
Is the object idle, and therefore can be despawned organically?
override void OnDespawned()
Raised when the object is 'despawned' back into the pool.
A drop in implementation of the Hydrogen.Core.ObjectPoolItem. This is one possible way of setting up ...
override void OnSpawned()
Raised when the object is 'spawned' from the pool.