Infohazard.Core 1.4.1
Infohazard Core Utility Library
Loading...
Searching...
No Matches
Infohazard.Core.DefaultPoolHandler Class Reference

An IPoolHandler that is passed a prefab directly. More...

Public Member Functions

 DefaultPoolHandler (Spawnable prefab, Transform transform)
 Construct DefaultPoolHandler for a given prefab, attached to a given Transform. More...
 
override string ToString ()
 
virtual Spawnable Spawn ()
 Spawn an object from the pool, using an inactive instance from the pool if possible (otherwise, a new instance is created via Instantiate). More...
 
virtual void Despawn (Spawnable instance)
 Despawn an object, deactivating it and releasing it back to the pool. More...
 
virtual void Retain ()
 Add an additional user to the pool, ensuring pooled instances will remain available. More...
 
virtual void Release ()
 Remove a user from the pool, clearing inactive instances if user count reaches zero. More...
 

Protected Member Functions

virtual void OnGet (Spawnable obj)
 Override to perform custom logic when an object is being spawned from the pool. More...
 
virtual void OnRelease (Spawnable obj)
 Override to perform custom logic when an object is being despawned and released back to the pool. More...
 
virtual Spawnable Instantiate ()
 Instantiate an object to add to the pool. Override to perform custom instantiation logic. More...
 
virtual void Destroy (Spawnable obj)
 Destroy an object after it is removed from the pool. Override to perform custom destruction logic. More...
 
void CheckClear ()
 Clear the pool if ShouldClear returns true. More...
 
virtual bool ShouldClear ()
 Should the pool be cleared? More...
 
virtual void Clear ()
 Clear all the inactive instances from the pool to free up memory. More...
 

Properties

Spawnable Prefab [get, protected set]
 The loaded prefab to be spawned by the handler. More...
 
Pool< SpawnablePool [get]
 The pool that will spawn the prefab. More...
 
Transform Transform [get]
 The transform that inactive instances in the pool are parented to. More...
 
virtual bool ShouldPool [get]
 Whether to use pooling - by default this returns Spawnable.Pooled. More...
 
int RetainCount [get, private set]
 

Detailed Description

An IPoolHandler that is passed a prefab directly.

Constructor & Destructor Documentation

◆ DefaultPoolHandler()

Infohazard.Core.DefaultPoolHandler.DefaultPoolHandler ( Spawnable  prefab,
Transform  transform 
)

Construct DefaultPoolHandler for a given prefab, attached to a given Transform.

Parameters
prefabPrefab that this handler will spawn.
transformTransform to attach inactive instances to.

Member Function Documentation

◆ CheckClear()

void Infohazard.Core.DefaultPoolHandler.CheckClear ( )
protected

Clear the pool if ShouldClear returns true.

◆ Clear()

virtual void Infohazard.Core.DefaultPoolHandler.Clear ( )
protectedvirtual

Clear all the inactive instances from the pool to free up memory.

◆ Despawn()

virtual void Infohazard.Core.DefaultPoolHandler.Despawn ( Spawnable  instance)
virtual

Despawn an object, deactivating it and releasing it back to the pool.

Parameters
instanceThe object to be despawned.

◆ Destroy()

virtual void Infohazard.Core.DefaultPoolHandler.Destroy ( Spawnable  obj)
protectedvirtual

Destroy an object after it is removed from the pool. Override to perform custom destruction logic.

This method is only used when an object is no longer needed and is permanently destroyed. To implement logic that happens every time an object is despawned, see OnRelease.

Parameters
objThe object to be destroyed.

◆ Instantiate()

virtual Spawnable Infohazard.Core.DefaultPoolHandler.Instantiate ( )
protectedvirtual

Instantiate an object to add to the pool. Override to perform custom instantiation logic.

This method is only used when a new object is needed and the pool is empty. To implement logic that happens every time an object is spawned, see OnGet. This method makes the spawned object inactive. If you implement your own instantiate logic instead of calling the base method, you should also make the object inactive.

Returns
The spawned object.

◆ OnGet()

virtual void Infohazard.Core.DefaultPoolHandler.OnGet ( Spawnable  obj)
protectedvirtual

Override to perform custom logic when an object is being spawned from the pool.

Invoked before the object is made active. This method is called every time a pooled object becomes active (including right after it is instantiated). To implement custom creation logic that only happens once per object, see Instantiate.

Parameters
objThe object being spawned.

◆ OnRelease()

virtual void Infohazard.Core.DefaultPoolHandler.OnRelease ( Spawnable  obj)
protectedvirtual

Override to perform custom logic when an object is being despawned and released back to the pool.

Invoked before the object is made inactive. This method is called every time a pooled object becomes inactive (included right before it is destroyed). To implement cleanup creation logic that only happens once per object, see Destroy(Spawnable).

Parameters
objThe object being spawned.

◆ Release()

virtual void Infohazard.Core.DefaultPoolHandler.Release ( )
virtual

Remove a user from the pool, clearing inactive instances if user count reaches zero.

When removing the last user, all inactive instances will be destroyed, and any additional calls to Spawn will need to create a new object via Instantiate.

◆ Retain()

virtual void Infohazard.Core.DefaultPoolHandler.Retain ( )
virtual

Add an additional user to the pool, ensuring pooled instances will remain available.

◆ ShouldClear()

virtual bool Infohazard.Core.DefaultPoolHandler.ShouldClear ( )
protectedvirtual

Should the pool be cleared?

The base implementation returns true if RetainCount == 0.

Returns
True if the pool should be cleared.

◆ Spawn()

virtual Spawnable Infohazard.Core.DefaultPoolHandler.Spawn ( )
virtual

Spawn an object from the pool, using an inactive instance from the pool if possible (otherwise, a new instance is created via Instantiate).

Returns
The spawned object.

◆ ToString()

override string Infohazard.Core.DefaultPoolHandler.ToString ( )

Property Documentation

◆ Pool

Pool<Spawnable> Infohazard.Core.DefaultPoolHandler.Pool
getprotected

The pool that will spawn the prefab.

◆ Prefab

Spawnable Infohazard.Core.DefaultPoolHandler.Prefab
getprotected set

The loaded prefab to be spawned by the handler.

◆ RetainCount

int Infohazard.Core.DefaultPoolHandler.RetainCount
getprivate set

◆ ShouldPool

virtual bool Infohazard.Core.DefaultPoolHandler.ShouldPool
get

Whether to use pooling - by default this returns Spawnable.Pooled.

◆ Transform

Transform Infohazard.Core.DefaultPoolHandler.Transform
get

The transform that inactive instances in the pool are parented to.


The documentation for this class was generated from the following file: