Skip to main content

class ObjectPool

(Niantic.Lightship.Maps.ObjectPools.ObjectPool)

Overview

A general-purpose object pool for types derived from Unity's UnityObject

	template <T>
class ObjectPool: IPooledObjectAccessor< T > {
public:
// methods

ObjectPool(
T source,
Action<T> onCreate = null,
Action<PooledObject<T>> onAcquire = null,
Action<T> onRelease = null
);

PooledObject<T> GetOrCreate();
};

Detailed Documentation

A general-purpose object pool for types derived from Unity's UnityObject

    Parameters:

    T - The pool's derived type

Methods

ObjectPool

ObjectPool(
T source,
Action<T> onCreate = null,
Action<PooledObject<T>> onAcquire = null,
Action<T> onRelease = null
)

Constructor

    Parameters:

    source - The object to be duplicated in the pool.

    onCreate - An action invoked on a newly instantiated object when it is first created.

    onAcquire - An action invoked on a new or reused object when it is acquired, before it is returned to the caller.

    onRelease - An action invoked on an object when it is released.

    ArgumentNullException - Thrown if source is null.

GetOrCreate

PooledObject<T> GetOrCreate()

Gets an object in the Pool if one is available. Otherwise, returns a new instance of the object and calls onCreate() on it.

    Returns:

    An object in the Pool, if one is available. Otherwise, a new instance of the object.