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

Attach this component to a prefab to enable it to use the pooling system. More...

Public Member Functions

void DespawnSelf ()
 Despawn this instance and return it to the PoolManager. More...
 

Static Public Member Functions

static Spawnable Spawn (Spawnable prefab, Vector3? position=null, Quaternion? rotation=null, Transform parent=null, bool inWorldSpace=false, ulong persistedInstanceID=0, Scene? scene=null)
 Spawn a new pooled instance with the given properties. More...
 
static Spawnable Spawn (Spawnable prefab, in SpawnParams spawnParams=default)
 Spawn a new pooled instance with the given properties. More...
 
static void Despawn (Spawnable instance, float inSeconds=0.0f)
 Despawn a pooled instance, optionally after some time has passed. More...
 
static GameObject Spawn (GameObject prefab, Vector3? position=null, Quaternion? rotation=null, Transform parent=null, bool inWorldSpace=false, ulong persistedInstanceID=0, Scene? scene=null)
 Spawn a new instance with the given properties, using the pooling system if the prefab has a Spawnable script. More...
 
static GameObject Spawn (GameObject prefab, in SpawnParams spawnParams=default)
 Spawn a new instance with the given properties, using the pooling system if the prefab has a Spawnable script. More...
 
static void Despawn (GameObject instance, float inSeconds=0.0f)
 Despawn an instance, optionally after some time has passed, using the pooling system if the prefab has a Spawnable script. More...
 
static T Spawn< T > (T prefab, Vector3? position=null, Quaternion? rotation=null, Transform parent=null, bool inWorldSpace=false, ulong persistedInstanceID=0, Scene? scene=null)
 Spawn a new instance with the given properties, using the pooling system if the prefab has a Spawnable script. More...
 
static T Spawn< T > (T prefab, in SpawnParams spawnParams=default)
 Spawn a new instance with the given properties, using the pooling system if the prefab has a Spawnable script. More...
 

Properties

bool Pooled [get]
 Whether this object should be pooled. More...
 
bool IsSpawned [get, private set]
 Whether or not this object is an active, spawned instance. More...
 
bool IsDespawned [get, private set]
 Whether or not this object is currently an inactive instance. More...
 
IPoolHandler PoolHandler [get, set]
 IPoolHandler which was used to spawn the object. More...
 

Events

Action< SpawnableSpawned
 Invoked when the Spawnable is spawned. More...
 
Action< SpawnableDespawned
 Invoke when the Spawnable is despawned. More...
 
Action< SpawnableDestroyed
 Invoked when the Spawnable is destroyed (not just despawned). More...
 

Detailed Description

Attach this component to a prefab to enable it to use the pooling system.

The static methods in this class are also the main way to spawn objects in a way that's compatible with the pooling system. When a Spawnable object is spawned, it will broadcast the OnSpawned message to its children. When it is despawned, it will broadcast the OnDespawned method.

Member Function Documentation

◆ Despawn() [1/2]

static void Infohazard.Core.Spawnable.Despawn ( GameObject  instance,
float  inSeconds = 0.0f 
)
static

Despawn an instance, optionally after some time has passed, using the pooling system if the prefab has a Spawnable script.

Parameters
instanceThe instance to despawn.
inSecondsThe time to wait before despawning. If zero, despawn is synchronous.

◆ Despawn() [2/2]

static void Infohazard.Core.Spawnable.Despawn ( Spawnable  instance,
float  inSeconds = 0.0f 
)
static

Despawn a pooled instance, optionally after some time has passed.

Parameters
instanceThe instance to despawn.
inSecondsThe time to wait before despawning. If zero, despawn is synchronous.

◆ DespawnSelf()

void Infohazard.Core.Spawnable.DespawnSelf ( )

Despawn this instance and return it to the PoolManager.

◆ Spawn() [1/4]

static GameObject Infohazard.Core.Spawnable.Spawn ( GameObject  prefab,
in SpawnParams  spawnParams = default 
)
static

Spawn a new instance with the given properties, using the pooling system if the prefab has a Spawnable script.

Parameters
prefabThe prefab to spawn.
spawnParamsSpawn properties.
Returns
The spawned instance.

◆ Spawn() [2/4]

static GameObject Infohazard.Core.Spawnable.Spawn ( GameObject  prefab,
Vector3?  position = null,
Quaternion?  rotation = null,
Transform  parent = null,
bool  inWorldSpace = false,
ulong  persistedInstanceID = 0,
Scene?  scene = null 
)
static

Spawn a new instance with the given properties, using the pooling system if the prefab has a Spawnable script.

Parameters
prefabThe prefab to spawn.
positionThe position to spawn at.
rotationThe rotation to spawn at.
parentThe parent to spawn under.
inWorldSpaceIf true, position/rotation are global, else they are local to parent.
persistedInstanceIDExisting persisted instance ID to assign.
sceneThe scene to spawn in.
Returns
The spawned instance.

◆ Spawn() [3/4]

static Spawnable Infohazard.Core.Spawnable.Spawn ( Spawnable  prefab,
in SpawnParams  spawnParams = default 
)
static

Spawn a new pooled instance with the given properties.

Parameters
prefabThe prefab to spawn.
spawnParamsSpawn properties.
Returns
The spawned instance.

◆ Spawn() [4/4]

static Spawnable Infohazard.Core.Spawnable.Spawn ( Spawnable  prefab,
Vector3?  position = null,
Quaternion?  rotation = null,
Transform  parent = null,
bool  inWorldSpace = false,
ulong  persistedInstanceID = 0,
Scene?  scene = null 
)
static

Spawn a new pooled instance with the given properties.

Parameters
prefabThe prefab to spawn.
positionThe position to spawn at.
rotationThe rotation to spawn at.
parentThe parent to spawn under.
inWorldSpaceIf true, position/rotation are global, else they are local to parent.
persistedInstanceIDExisting persisted instance ID to assign.
sceneThe scene to spawn in.
Returns
The spawned instance.

◆ Spawn< T >() [1/2]

static T Infohazard.Core.Spawnable.Spawn< T > ( prefab,
in SpawnParams  spawnParams = default 
)
static

Spawn a new instance with the given properties, using the pooling system if the prefab has a Spawnable script.

Parameters
prefabThe prefab to spawn.
spawnParamsSpawn properties.
Returns
The spawned instance.
Type Constraints
T :Component 

◆ Spawn< T >() [2/2]

static T Infohazard.Core.Spawnable.Spawn< T > ( prefab,
Vector3?  position = null,
Quaternion?  rotation = null,
Transform  parent = null,
bool  inWorldSpace = false,
ulong  persistedInstanceID = 0,
Scene?  scene = null 
)
static

Spawn a new instance with the given properties, using the pooling system if the prefab has a Spawnable script.

Parameters
prefabThe prefab to spawn.
positionThe position to spawn at.
rotationThe rotation to spawn at.
parentThe parent to spawn under.
inWorldSpaceIf true, position/rotation are global, else they are local to parent.
persistedInstanceIDExisting persisted instance ID to assign.
sceneThe scene to spawn in.
Returns
The spawned instance.
Type Constraints
T :Component 

Property Documentation

◆ IsDespawned

bool Infohazard.Core.Spawnable.IsDespawned
getprivate set

Whether or not this object is currently an inactive instance.

◆ IsSpawned

bool Infohazard.Core.Spawnable.IsSpawned
getprivate set

Whether or not this object is an active, spawned instance.

◆ Pooled

bool Infohazard.Core.Spawnable.Pooled
get

Whether this object should be pooled.

◆ PoolHandler

IPoolHandler Infohazard.Core.Spawnable.PoolHandler
getsetpackage

IPoolHandler which was used to spawn the object.

Event Documentation

◆ Despawned

Action<Spawnable> Infohazard.Core.Spawnable.Despawned

Invoke when the Spawnable is despawned.

◆ Destroyed

Action<Spawnable> Infohazard.Core.Spawnable.Destroyed

Invoked when the Spawnable is destroyed (not just despawned).

◆ Spawned

Action<Spawnable> Infohazard.Core.Spawnable.Spawned

Invoked when the Spawnable is spawned.


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