SerialisableGameObjectPool Class |
[This is preliminary documentation and is subject to change.]
Namespace: Umbrace.Unity.PurePool
[SerializableAttribute] public class SerialisableGameObjectPool : SerialisableObjectPool<GameObject>
The SerialisableGameObjectPool type exposes the following members.
Name | Description | |
---|---|---|
![]() | SerialisableGameObjectPool |
Initialises a new instance of the SerialisableGameObjectPool class.
|
Name | Description | |
---|---|---|
![]() | CanAcquire | Gets a value indicating whether an instance can be acquired from the pool. An instance can be acquired when the pool contains at least one instance, or when InstantiateWhenEmpty is true. |
![]() | Count |
Gets the number of objects currently contained by the pool.
(Inherited from SerialisableObjectPool<T>.) |
![]() | InitialSize |
Gets or sets the initial size of the pool. Cannot be set once the pool has been initialised.
(Inherited from SerialisableObjectPool<T>.) |
![]() | InstantiateWhenEmpty |
Gets or sets a value indicating whether to instantiate a new object when the pool is empty, and an attempt is made to acquire from the pool.
(Inherited from SerialisableObjectPool<T>.) |
![]() | IsEmpty |
Gets a value indicating whether the pool is empty and contains no objects.
(Inherited from SerialisableObjectPool<T>.) |
![]() | IsFull |
Gets a value indicating whether the pool is full, and cannot contain any more objects.
(Inherited from SerialisableObjectPool<T>.) |
![]() | IsInitialised |
Gets a value indicating whether the pool has been initialised.
(Inherited from SerialisableObjectPool<T>.) |
![]() | Items |
Gets a list of items currently contained by the pool.
(Inherited from SerialisableObjectPool<T>.) |
![]() | LogMessages |
Gets or sets the level of log messaging that the pool will output.
(Inherited from SerialisableObjectPool<T>.) |
![]() | MaximumSize |
Gets or sets the maximum size of the pool, which is the maximum number of objects it can contain.
(Inherited from SerialisableObjectPool<T>.) |
![]() | NotificationMode |
Gets or sets the way in which pooled objects are notified about being acquired from, and returned to, the pool.
Cannot be set once the pool has been initialised.
|
![]() | Parent |
Gets or sets the parent transform to which all pooled objects will be parented in the hierarchy,
if ReparentPooledObjects is true.
|
![]() | RecordStatistics |
Gets or sets a value indicating whether to record pool statistics.
(Inherited from SerialisableObjectPool<T>.) |
![]() | RefillPoolOnReinitialise |
Gets a value indiciating whether to refill the pool with new objects after the pool is reinitialised,
as happens from deserialisation.
(Overrides SerialisableObjectPool<T>.RefillPoolOnReinitialise.) |
![]() | ReparentPooledObjects |
Gets or sets a value indicating whether to re-parent the pooled objects to the Parent transform,
after the objects are returned to the pool.
|
![]() | SourceObject |
Gets the source object that is being pooled.
|
![]() | Statistics |
Gets an object containing general operational statistics about the pool.
(Inherited from SerialisableObjectPool<T>.) |
![]() | WarnOnDestroy |
Gets or sets a value indicating whether to log a warning message when a poolable object is destroyed (either inside of the pool, or while in use).
|
Name | Description | |
---|---|---|
![]() | Acquire() |
Acquires an object from the pool.
(Inherited from SerialisableObjectPool<T>.) |
![]() | Acquire(Transform) |
Acquires an instance of the source object, and sets its parent transform.
|
![]() | Acquire(Transform, Boolean) |
Acquires an instance of the source object, and sets its parent transform.
|
![]() | Acquire(Vector3, Quaternion) |
Acquires an instance of the source object, and sets its position and rotation.
|
![]() | Acquire(Vector3, Quaternion, Transform) |
Acquires an instance of the source object, and sets its parent transform, position and rotation.
|
![]() | Clear |
Clears the pool, emptying it of all pooled objects.
(Inherited from SerialisableObjectPool<T>.) |
![]() | Contains |
Determines whether an instance is in the pool.
(Inherited from SerialisableObjectPool<T>.) |
![]() | Equals | (Inherited from Object.) |
![]() | Fill |
Fills the pool, populating it with pooled objects until it reaches the maximum pool size.
(Inherited from SerialisableObjectPool<T>.) |
![]() | Finalize | (Inherited from Object.) |
![]() | GetHashCode | (Inherited from Object.) |
![]() | GetItems |
Gets a list of items currently contained by the pool, and stores them in the specified List<T>.
(Inherited from SerialisableObjectPool<T>.) |
![]() | GetObjectFactory |
Gets a function used to create new instances of the pooled type.
By default, this method uses the public parameterless constructor of type T.
This method should be overridden in a subclass if different behaviour is required.
(Overrides SerialisableObjectPool<T>.GetObjectFactory().) |
![]() | GetType | (Inherited from Object.) |
![]() | Initialise() |
Initialises the pool, populating it with objects and making it ready for use.
(Inherited from SerialisableObjectPool<T>.) |
![]() | Initialise(Boolean) |
Initialises the pool, making it ready for use, and optionally populating it with objects.
(Inherited from SerialisableObjectPool<T>.) |
![]() | MemberwiseClone | (Inherited from Object.) |
![]() | OnAfterDeserialize |
Performs actions after the object has been deserialised.
(Overrides SerialisableObjectPool<T>.OnAfterDeserialize().) |
![]() | OnBeforeSerialize |
Performs actions prior to the object being serialised.
(Overrides SerialisableObjectPool<T>.OnBeforeSerialize().) |
![]() | OnCanAcquireChanged |
Raises the CanAcquireChanged event.
(Inherited from SerialisableObjectPool<T>.) |
![]() | OnCountChanged |
Raises the CountChanged event.
(Inherited from SerialisableObjectPool<T>.) |
![]() | OnInitialised |
Raises the Initialised event.
(Inherited from SerialisableObjectPool<T>.) |
![]() | OnObjectAcquired |
Raises the ObjectAcquired event.
(Overrides SerialisableObjectPool<T>.OnObjectAcquired(T, Boolean).) |
![]() | OnObjectDestroyed |
Raises the ObjectDestroyed event.
(Overrides SerialisableObjectPool<T>.OnObjectDestroyed(T).) |
![]() | OnObjectInstantiated |
Raises the ObjectInstantiated event.
(Inherited from SerialisableObjectPool<T>.) |
![]() | OnObjectReleased |
Raises the ObjectReleased event.
(Overrides SerialisableObjectPool<T>.OnObjectReleased(T, Boolean).) |
![]() | Release |
Releases an object back to the pool.
(Inherited from SerialisableObjectPool<T>.) |
![]() | ReleaseInternal |
Releases an object back to the pool.
(Overrides SerialisableObjectPool<T>.ReleaseInternal(T).) |
![]() | Remove |
Removes the specified instance from the pool.
(Inherited from SerialisableObjectPool<T>.) |
![]() | SetSize |
Sets the number of objects contained by the pool, either destroying excess pooled objects, or instantiating new ones.
(Inherited from SerialisableObjectPool<T>.) |
![]() | ToString | (Inherited from Object.) |
![]() | TryAcquire(T) |
Acquires an object from the pool.
(Inherited from SerialisableObjectPool<T>.) |
![]() | TryAcquire(Transform, GameObject) |
Acquires an instance of the source object, and sets its parent transform.
|
![]() | TryAcquire(Transform, Boolean, GameObject) |
Acquires an instance of the source object, and sets its parent transform.
|
![]() | TryAcquire(Vector3, Quaternion, GameObject) |
Acquires an instance of the source object, and sets its position and rotation.
|
![]() | TryAcquire(Vector3, Quaternion, Transform, GameObject) |
Acquires an instance of the source object, and sets its parent transform, position and rotation.
|
Name | Description | |
---|---|---|
![]() | CanAcquireChanged |
Occurs when the value of CanAcquire changes.
(Inherited from SerialisableObjectPool<T>.) |
![]() | CountChanged |
Occurs when Count changes.
(Inherited from SerialisableObjectPool<T>.) |
![]() | Initialised |
Occurs when the pool is initialised.
(Inherited from SerialisableObjectPool<T>.) |
![]() | ObjectAcquired |
Occurs when an object is acquired from the pool.
(Inherited from SerialisableObjectPool<T>.) |
![]() | ObjectDestroyed |
Occurs when an object is destroyed.
(Inherited from SerialisableObjectPool<T>.) |
![]() | ObjectInstantiated |
Occurs when a new object is instantiated.
(Inherited from SerialisableObjectPool<T>.) |
![]() | ObjectReleased |
Occurs when an object is released back to the pool.
(Inherited from SerialisableObjectPool<T>.) |
By virtue of being serialisable, SerialisableGameObjectPool can survive an assembly reload caused by live recompilation inside of the Unity editor.
SerialisableGameObjectPool achieves this by serialising the instances of the object that were contained in the pool, and then re-adding them to the pool after deserialisation.
To use the SerialisableGameObjectPool, initialise a new instance using the constructor, and then set the properties to appropriate values. Once all properties have been set, invoke the Initialise() method. A pool cannot be used without being initialised in this way.
// Create the pool. var pool = new SerialisableGameObjectPool(prefab, parentContainer) { InitialSize = 50, MaximumSize = 200, InstantiateWhenEmpty = true, NotificationMode = NotificationMode.Interface, LogMessages = LogLevel.Warning }; // Initialise the pool. It will contain 50 objects. pool.Initialise(); // Acquire one of the 50 objects from the pool. The Acquire method can be used safely if InstantiateWhenEmpty is true, or if a check is made to CanAcquire beforehand. GameObject instance = pool.Acquire(); // Acquire one of the 49 remaining objects from the pool. TryAcquire can be used safely even when InstantiateWhenEmpty is false. GameObject secondInstance; if (pool.TryAcquire(out secondInstance)) { // Release the object back to the pool. It now contains 49 objects again. pool.Release(secondInstance); } // Release the object back to the pool. It now contains 50 objects. pool.Release(instance);