SerialisableObjectPoolT Class |
[This is preliminary documentation and is subject to change.]
Namespace: Umbrace.Unity.PurePool
[SerializableAttribute] public abstract class SerialisableObjectPool<T> : ISerializationCallbackReceiver, IObjectPool<T>, IObjectPool
The SerialisableObjectPoolT type exposes the following members.
Name | Description | |
---|---|---|
SerialisableObjectPoolT |
Initialises a new instance of the SerialisableObjectPoolT 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 . | |
Count |
Gets the number of objects currently contained by the pool.
| |
InitialSize |
Gets or sets the initial size of the pool. Cannot be set once the pool has been initialised.
| |
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.
| |
IsEmpty |
Gets a value indicating whether the pool is empty and contains no objects.
| |
IsFull |
Gets a value indicating whether the pool is full, and cannot contain any more objects.
| |
IsInitialised |
Gets a value indicating whether the pool has been initialised.
| |
Items |
Gets a list of items currently contained by the pool.
| |
LogMessages |
Gets or sets the level of log messaging that the pool will output.
| |
MaximumSize |
Gets or sets the maximum size of the pool, which is the maximum number of objects it can contain.
| |
RecordStatistics |
Gets or sets a value indicating whether to record pool statistics.
| |
RefillPoolOnReinitialise |
Gets a value indiciating whether to refill the pool with new objects after the pool is reinitialised,
as happens from deserialisation.
| |
Statistics |
Gets an object containing general operational statistics about the pool.
|
Name | Description | |
---|---|---|
Acquire |
Acquires an object from the pool.
| |
Clear |
Clears the pool, emptying it of all pooled objects.
| |
Contains |
Determines whether an instance is in the pool.
| |
Equals | (Inherited from Object.) | |
Fill |
Fills the pool, populating it with pooled objects until it reaches the maximum pool size.
| |
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.
| |
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.
| |
GetType | (Inherited from Object.) | |
Initialise |
Initialises the pool, populating it with objects and making it ready for use.
| |
Initialise(Boolean) |
Initialises the pool, making it ready for use, and optionally populating it with objects.
| |
MemberwiseClone | (Inherited from Object.) | |
OnAfterDeserialize |
Performs actions after the object has been deserialised.
| |
OnBeforeSerialize |
Performs actions prior to the object being serialised.
| |
OnCanAcquireChanged |
Raises the CanAcquireChanged event.
| |
OnCountChanged |
Raises the CountChanged event.
| |
OnInitialised |
Raises the Initialised event.
| |
OnObjectAcquired |
Raises the ObjectAcquired event.
| |
OnObjectDestroyed |
Raises the ObjectDestroyed event.
| |
OnObjectInstantiated |
Raises the ObjectInstantiated event.
| |
OnObjectReleased |
Raises the ObjectReleased event.
| |
Release |
Releases an object back to the pool.
| |
ReleaseInternal |
Releases an object back to the pool.
| |
Remove |
Removes the specified instance from the pool.
| |
SetSize |
Sets the number of objects contained by the pool, either destroying excess pooled objects, or instantiating new ones.
| |
ToString | (Inherited from Object.) | |
TryAcquire |
Acquires an object from the pool.
|
Name | Description | |
---|---|---|
CanAcquireChanged |
Occurs when the value of CanAcquire changes.
| |
CountChanged |
Occurs when Count changes.
| |
Initialised |
Occurs when the pool is initialised.
| |
ObjectAcquired |
Occurs when an object is acquired from the pool.
| |
ObjectDestroyed |
Occurs when an object is destroyed.
| |
ObjectInstantiated |
Occurs when a new object is instantiated.
| |
ObjectReleased |
Occurs when an object is released back to the pool.
|
Name | Description | |
---|---|---|
DefaultInitialSize |
The default initial size of newly-created pools.
| |
DefaultMaximumPoolSize |
The default maximum size of newly-created pools.
|
By virtue of being serialisable, SerialisableObjectPoolT can survive an assembly reload caused by live recompilation inside of the Unity editor. However, to ensure Unity is able to serialise fields containing pools, you should subclass SerialisableObjectPoolT by creating a new, non-generic, class derived from it.
SerialisableObjectPoolT achieves this by serialising the number of instances of the object that were contained in the pool, and then recreating them after deserialisation. In other cases, it's possible to let Unity serialise the objects contained in the pool, and simply add them back into the pool after deserialisation.
To use the SerialisableObjectPoolT, derive a new, non-generic, class from it and override the GetObjectFactory method. This method is responsible for providing an object factory that can create new instances of the desired object. Initialise a new instance of the derived class 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.