Hydrogen Framework  1.3.1
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events
hObjectPoolItem Class Reference

A drop in implementation of the Hydrogen.Core.ObjectPoolItem. This is one possible way of setting up an ObjectPoolItem to handle spawning and despawning appropriately. More...

+ Inheritance diagram for hObjectPoolItem:

Public Member Functions

override void DespawnSafely ()
 Despawn the gameObject safely after all particles have done their thing. More...
 
override bool IsInactive ()
 Is the object idle, and therefore can be despawned organically? More...
 
override void OnDespawned ()
 Raised when the object is 'despawned' back into the pool. More...
 
override void OnSpawned ()
 Raised when the object is 'spawned' from the pool. More...
 

Public Attributes

float LifeTime
 Despawn gameObject after this number of seconds. More...
 

Detailed Description

A drop in implementation of the Hydrogen.Core.ObjectPoolItem. This is one possible way of setting up an ObjectPoolItem to handle spawning and despawning appropriately.

Learn from it, make your own, as long as you extend from the base class you still get the performance benefits.

Definition at line 41 of file hObjectPoolItem.cs.

Member Function Documentation

override void hObjectPoolItem.DespawnSafely ( )
virtual

Despawn the gameObject safely after all particles have done their thing.

If you are going to utilize this make sure that your function contains: hObjectPool.Instance.objectPools[poolID].DespawnImmediate(gameObject);

Implements Hydrogen.Core.ObjectPoolItemBase.

Definition at line 54 of file hObjectPoolItem.cs.

55  {
56  StartCoroutine (WaitForParticles ());
57  }
override bool hObjectPoolItem.IsInactive ( )
virtual

Is the object idle, and therefore can be despawned organically?

Returns
true

false

This will only work on tracked spawned objects.

Implements Hydrogen.Core.ObjectPoolItemBase.

Definition at line 65 of file hObjectPoolItem.cs.

66  {
67  // A simple rigidbody check, otherwise no bueno
68  return ParentPool.HasRigidbody && gameObject.rigidbody.IsSleeping ();
69  }
override void hObjectPoolItem.OnDespawned ( )
virtual

Raised when the object is 'despawned' back into the pool.

It does not set "active", you must handle that yourself.

Implements Hydrogen.Core.ObjectPoolItemBase.

Definition at line 75 of file hObjectPoolItem.cs.

76  {
77  // If our object has a rigidbody (cached check), make sure to zero its velocity.
78  if (ParentPool.HasRigidbody)
79  gameObject.rigidbody.velocity = Vector3.zero;
80 
81  // Disable the gameObject
82  gameObject.SetActive (false);
83  }
override void hObjectPoolItem.OnSpawned ( )
virtual

Raised when the object is 'spawned' from the pool.

It does not set "active", you must handle that yourself.

Implements Hydrogen.Core.ObjectPoolItemBase.

Definition at line 89 of file hObjectPoolItem.cs.

90  {
91  // Make sure our object is active please and thank you
92  gameObject.SetActive (true);
93 
94  // If there is a LifeTime greater then 0, we set a timer to despawn
95  if (LifeTime > 0)
96  StartCoroutine (DespawnTimer ());
97  }
float LifeTime
Despawn gameObject after this number of seconds.

Member Data Documentation

float hObjectPoolItem.LifeTime

Despawn gameObject after this number of seconds.

In seconds, use 0 to disable.

Definition at line 47 of file hObjectPoolItem.cs.