Click or drag to resize

PoolBaseTSource, TInstance, TSettings Class

[This is preliminary documentation and is subject to change.]

An abstract MonoBehaviour component that provides shared functionality for the pooling of many instances of a type, allowing the instances to be recycled and reused.
Inheritance Hierarchy
SystemObject
  UnityEngineObject
    UnityEngineComponent
      UnityEngineBehaviour
        UnityEngineMonoBehaviour
          Umbrace.Unity.PurePoolPoolBaseTSource, TInstance, TSettings
            Umbrace.Unity.PurePoolComponentPool
            Umbrace.Unity.PurePoolGameObjectPool

Namespace:  Umbrace.Unity.PurePool
Assembly:  Umbrace.Unity.PurePool (in Umbrace.Unity.PurePool.dll) Version: 0.0.0.0 (1.0.0.0)
Syntax
C#
public abstract class PoolBase<TSource, TInstance, TSettings> : MonoBehaviour, 
	ISharedPoolSettings<TSource>, ISharedPoolSettings, IObjectPool<TInstance>, IObjectPool, 
	IPoolBase, ISerializationCallbackReceiver
where TSettings : new(), SharedPoolSettings<TSource>

Type Parameters

TSource
The type of the source object to be pooled.
TInstance
The type of the instances of a pooled object.
TSettings
The type of the pool settings.

The PoolBaseTSource, TInstance, TSettings type exposes the following members.

Constructors
  NameDescription
Protected methodPoolBaseTSource, TInstance, TSettings
Initializes a new instance of the PoolBaseTSource, TInstance, TSettings class
Top
Properties
  NameDescription
Public propertyCanAcquire

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 .

Public propertyCount
Gets the number of objects currently contained by the pool.
Public propertyDefinition
Gets the settings that were used to initialise this pool.
Public propertyDontDestroyOnLoad
Gets or sets a value indicating whether the pool should persist between scene changes.
Public propertyEnabled
Gets or sets a value indicating whether pooling is enabled.
Public propertyInitialiseOnStart
Gets or sets a value indicating whether to initialise the pool in the MonoBehaviour Start method. Cannot be set once the pool has been initialised.
Public propertyInitialSize
Gets or sets the initial size of the pool. Cannot be set once the pool has been initialised.
Public propertyInstantiateWhenEmpty
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.
Public propertyIsEmpty
Gets a value indicating whether the pool is empty and contains no objects.
Public propertyIsInitialised
Gets a value indicating whether the pool has been initialised.
Public propertyItems
Gets a list of items currently contained by the pool.
Public propertyLogMessages
Gets or sets the level of log messaging that the pool will output.
Public propertyMaximumSize
Gets or sets the maximum size of the pool, which is the maximum number of objects it can contain.
Public propertyNotificationMode
Gets or sets the modes in which pooled objects are notified of their acquisition from, and release to, the pool.
Protected propertyPool
When implemented in a derived class, gets or sets the internal object pool.
Public propertyRecordStatistics
Gets or sets a value indicating whether to record pool statistics.
Public propertyReparentPooledObjects
Gets or sets a value indicating whether to re-parent the pooled objects to the pool's Transform, after the objects are returned to the pool.
Public propertySource
Gets or sets the source object that will be pooled.
Public propertyStatistics
Gets an object containing general operational statistics about the pool.
Public propertyWarnOnDestroy
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).
Top
Methods
  NameDescription
Public methodAcquire
Acquires an instance from the pool.
Protected methodCanInitialise
When overridden in a derived class, determines whether the pool can be initialised.
Public methodClear
Clears the pool, emptying it of all pooled objects.
Protected methodCreateInternalPool
When implemented in a derived class, creates the internal object pool.
Protected methodCreateSettingsClone
When implemented in a derived class, creates a new instance of TSettings that is an exact copy of the specified settings.
Protected methodDestroyInstance
When implemented in a derived class, destroys the specified instance.
Public methodEquals (Inherited from Object.)
Public methodFill
Fills the pool, populating it with pooled objects until it reaches the maximum pool size.
Protected methodFinalize (Inherited from Object.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetItems
Public methodGetType (Inherited from Object.)
Public methodGrow
Increases the number of objects contained by the pool by the specified amount.
Public methodInitialise
Initialises the pool, populating it with the initial number of objects.
Public methodInitialise(TSettings)
Initialises the pool, populating it with the initial number of objects.
Protected methodMemberwiseClone (Inherited from Object.)
Protected methodOnCanAcquireChanged
Raises the CanAcquireChanged event.
Protected methodOnCountChanged
Raises the CountChanged event.
Protected methodOnDestroy
Protected methodOnDestroyed
Raises the Destroyed event.
Protected methodOnInitialised
Raises the Initialised event.
Protected methodOnObjectAcquired
Raises the ObjectAcquired event.
Protected methodOnObjectDestroyed
Raises the ObjectDestroyed event.
Protected methodOnObjectInstantiated
Raises the ObjectInstantiated event.
Protected methodOnObjectReleased
Raises the ObjectReleased event.
Public methodRelease
Releases an instance back to the pool.
Public methodSetSize
Sets the number of objects contained by the pool, either destroying excess pooled objects, or instantiating new ones.
Public methodShrink
Decreases the number of objects contained by the pool by the specified amount.
Protected methodStart
Public methodToString (Inherited from Object.)
Public methodTryAcquire
Acquires an instance from the pool.
Top
Events
  NameDescription
Public eventCanAcquireChanged
Occurs when the value of CanAcquire changes.
Public eventCountChanged
Occurs when Count changes.
Public eventDestroyed
Occurs when the pool is destroyed.
Public eventInitialised
Occurs when the pool is initialised.
Public eventObjectAcquired
Occurs when an instance of the source object is acquired from the pool.
Public eventObjectDestroyed
Occurs when an instance of the source object is destroyed.
Public eventObjectInstantiated
Occurs when a new instance of the source object is instantiated.
Public eventObjectReleased
Occurs when an instance of the source object is released back to the pool.
Top
Remarks

By virtue of being serialisable, PoolBaseTSource, TInstance, TSettings can survive an assembly reload caused by live recompilation inside of the Unity editor.

TSource and TInstance may differ in the case of a source that is a Type. For example, a TSource of Type where the provided source is typeof(Component), will result in instances of Component, and therefore TInstance should be Component.

See Also