SerialisableComponentPool Class |
[This is preliminary documentation and is subject to change.]
Namespace: Umbrace.Unity.PurePool
[SerializableAttribute] public class SerialisableComponentPool : SerialisableGenericComponentPool<Component>
The SerialisableComponentPool type exposes the following members.
Name | Description | |
---|---|---|
SerialisableComponentPool |
Initialises a new instance of the SerialisableComponentPool class.
|
Name | Description | |
---|---|---|
AdditionalComponentTypes |
Gets a list of additional component types, that should be added to the same GameObject as the main component type.
(Inherited from SerialisableGenericComponentPoolT.) | |
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 . | |
ComponentType |
Gets the type of the component being pooled.
(Overrides SerialisableGenericComponentPoolTComponentType.) | |
Count |
Gets the number of objects currently contained by the pool.
(Inherited from SerialisableObjectPoolT.) | |
InitialSize |
Gets or sets the initial size of the pool. Cannot be set once the pool has been initialised.
(Inherited from SerialisableObjectPoolT.) | |
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 SerialisableObjectPoolT.) | |
IsEmpty |
Gets a value indicating whether the pool is empty and contains no objects.
(Inherited from SerialisableObjectPoolT.) | |
IsFull |
Gets a value indicating whether the pool is full, and cannot contain any more objects.
(Inherited from SerialisableObjectPoolT.) | |
IsInitialised |
Gets a value indicating whether the pool has been initialised.
(Inherited from SerialisableObjectPoolT.) | |
Items |
Gets a list of items currently contained by the pool.
(Inherited from SerialisableObjectPoolT.) | |
LogMessages |
Gets or sets the level of log messaging that the pool will output.
(Inherited from SerialisableObjectPoolT.) | |
MaximumSize |
Gets or sets the maximum size of the pool, which is the maximum number of objects it can contain.
(Inherited from SerialisableObjectPoolT.) | |
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.
(Inherited from SerialisableGenericComponentPoolT.) | |
Parent |
Gets or sets the parent transform to which all pooled objects will be parented in the hierarchy,
if ReparentPooledObjects is .
(Inherited from SerialisableGenericComponentPoolT.) | |
RecordStatistics |
Gets or sets a value indicating whether to record pool statistics.
(Inherited from SerialisableObjectPoolT.) | |
RefillPoolOnReinitialise |
Gets a value indiciating whether to refill the pool with new components after the pool is reinitialised,
as happens from deserialisation.
(Inherited from SerialisableGenericComponentPoolT.) | |
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.
(Inherited from SerialisableGenericComponentPoolT.) | |
Statistics |
Gets an object containing general operational statistics about the pool.
(Inherited from SerialisableObjectPoolT.) | |
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).
(Inherited from SerialisableGenericComponentPoolT.) |
Name | Description | |
---|---|---|
AcquireT |
Acquires an instance of the component.
| |
AcquireT(Transform) |
Acquires an instance of the component, and sets the parent transform of its GameObject.
| |
AcquireT(Vector3, Quaternion) |
Acquires an instance of the component, and sets the position and rotation of its GameObject.
| |
AcquireT(Transform, Vector3, Quaternion) |
Acquires an instance of the component, and sets the parent transform, position and rotation of its GameObject.
| |
CheckTypeT |
A conditionally-compiled helper method that checks if the type T is assignable from ComponentType.
| |
Clear |
Clears the pool, emptying it of all pooled objects.
(Inherited from SerialisableObjectPoolT.) | |
Contains |
Determines whether an instance is in the pool.
(Inherited from SerialisableObjectPoolT.) | |
Equals | (Inherited from Object.) | |
Fill |
Fills the pool, populating it with pooled objects until it reaches the maximum pool size.
(Inherited from SerialisableObjectPoolT.) | |
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 ListT.
(Inherited from SerialisableObjectPoolT.) | |
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.
(Inherited from SerialisableGenericComponentPoolT.) | |
GetType | (Inherited from Object.) | |
Initialise |
Initialises the pool, populating it with objects and making it ready for use.
(Inherited from SerialisableObjectPoolT.) | |
Initialise(Boolean) |
Initialises the pool, making it ready for use, and optionally populating it with objects.
(Inherited from SerialisableObjectPoolT.) | |
MemberwiseClone | (Inherited from Object.) | |
OnAfterDeserialize |
Performs actions after the object has been deserialised.
(Inherited from SerialisableGenericComponentPoolT.) | |
OnBeforeSerialize |
Performs actions prior to the object being serialised.
(Inherited from SerialisableGenericComponentPoolT.) | |
OnCanAcquireChanged |
Raises the CanAcquireChanged event.
(Inherited from SerialisableObjectPoolT.) | |
OnCountChanged |
Raises the CountChanged event.
(Inherited from SerialisableObjectPoolT.) | |
OnInitialised |
Raises the Initialised event.
(Inherited from SerialisableObjectPoolT.) | |
OnObjectAcquired |
Raises the ObjectAcquired event.
(Inherited from SerialisableGenericComponentPoolT.) | |
OnObjectDestroyed |
Raises the ObjectDestroyed event.
(Inherited from SerialisableGenericComponentPoolT.) | |
OnObjectInstantiated |
Raises the ObjectInstantiated event.
(Inherited from SerialisableObjectPoolT.) | |
OnObjectReleased |
Raises the ObjectReleased event.
(Inherited from SerialisableGenericComponentPoolT.) | |
Release |
Releases an object back to the pool.
(Inherited from SerialisableObjectPoolT.) | |
ReleaseInternal |
Releases an object back to the pool.
(Inherited from SerialisableGenericComponentPoolT.) | |
Remove |
Removes the specified instance from the pool.
(Inherited from SerialisableObjectPoolT.) | |
SetSize |
Sets the number of objects contained by the pool, either destroying excess pooled objects, or instantiating new ones.
(Inherited from SerialisableObjectPoolT.) | |
ToString | (Inherited from Object.) | |
TryAcquire(T) |
Acquires an object from the pool.
(Inherited from SerialisableObjectPoolT.) | |
TryAcquire(Transform, T) |
Acquires an instance of the component, and sets the parent transform of its GameObject.
(Inherited from SerialisableGenericComponentPoolT.) | |
TryAcquire(Vector3, Quaternion, T) |
Acquires an instance of the component, and sets the position and rotation of its GameObject.
(Inherited from SerialisableGenericComponentPoolT.) | |
TryAcquire(Transform, Vector3, Quaternion, T) |
Acquires an instance of the component, and sets the parent transform, position and rotation of its GameObject.
(Inherited from SerialisableGenericComponentPoolT.) | |
TryAcquireT(T) |
Acquires an instance of the component.
| |
TryAcquireT(Transform, T) |
Acquires an instance of the component, and sets the parent transform of its GameObject.
| |
TryAcquireT(Vector3, Quaternion, T) |
Acquires an instance of the component, and sets the position and rotation of its GameObject.
| |
TryAcquireT(Transform, Vector3, Quaternion, T) |
Acquires an instance of the component, and sets the parent transform, position and rotation of its GameObject.
|
Name | Description | |
---|---|---|
CanAcquireChanged |
Occurs when the value of CanAcquire changes.
(Inherited from SerialisableObjectPoolT.) | |
CountChanged |
Occurs when Count changes.
(Inherited from SerialisableObjectPoolT.) | |
Initialised |
Occurs when the pool is initialised.
(Inherited from SerialisableObjectPoolT.) | |
ObjectAcquired |
Occurs when an object is acquired from the pool.
(Inherited from SerialisableObjectPoolT.) | |
ObjectDestroyed |
Occurs when an object is destroyed.
(Inherited from SerialisableObjectPoolT.) | |
ObjectInstantiated |
Occurs when a new object is instantiated.
(Inherited from SerialisableObjectPoolT.) | |
ObjectReleased |
Occurs when an object is released back to the pool.
(Inherited from SerialisableObjectPoolT.) |
By virtue of being serialisable, SerialisableComponentPool can survive an assembly reload caused by live recompilation inside of the Unity editor.
SerialisableComponentPool achieves this by serialising the instances of the component that were contained in the pool, and then re-adding them to the pool after deserialisation.
To use the SerialisableComponentPool, 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 SerialisableComponentPool(typeof(AudioSource), 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 components from the pool. The Acquire method can be used safely if InstantiateWhenEmpty is true, or if a check is made to CanAcquire beforehand. AudioSource instance = pool.Acquire<AudioSource>(); // Acquire one of the 49 remaining components from the pool. TryAcquire can be used safely even when InstantiateWhenEmpty is false. AudioSource secondInstance; if (pool.TryAcquire(out secondInstance)) { // Release the component back to the pool. It now contains 49 objects again. pool.Release(secondInstance); } // Release the component back to the pool. It now contains 50 objects. pool.Release(instance);