Class PrefabPool
Inheritance
Namespace: Atlas
Assembly: Atlas.Runtime.dll
Syntax
public sealed class PrefabPool
Constructors
| Improve this Doc View SourcePrefabPool(Transform)
Constructor
Declaration
public PrefabPool(Transform pooledObjectsParent)
Parameters
Type | Name | Description |
---|---|---|
UnityEngine.Transform | pooledObjectsParent | Transform to use for parenting objects currently in the pool's reserve |
Properties
| Improve this Doc View SourceObjectCount
Total number of objects this pool has internally instantiated
Declaration
public int ObjectCount { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Methods
| Improve this Doc View SourceDestroy<T>(T)
Returns the given object instance to the pool for recycling
Declaration
public void Destroy<T>(T instance)
where T : Component, IPoolable
Parameters
Type | Name | Description |
---|---|---|
T | instance | The instance to return to the pool |
Type Parameters
Name | Description |
---|---|
T | The object's prefab type |
Remarks
OnDestroy will not get called when returning objects to the pool. Instead, use OnPoolDestroy() for per-object cleanup code
Instantiate<T>(T)
Returns an instanced copy of the given prefab object. If the pool is empty, a new object will be instantiated, otherwise a recycled object will be re-used.
Declaration
public T Instantiate<T>(T prefab)
where T : Component, IPoolable
Parameters
Type | Name | Description |
---|---|---|
T | prefab | Object prefab to make a copy of |
Returns
Type | Description |
---|---|
T | The instantiated/recycled clone |
Type Parameters
Name | Description |
---|---|
T | The object's prefab type |
Remarks
Awake/Start will not get called on recycled objects. Instead, use OnPoolInstantiate() for per-object startup code
Instantiate<T>(T, Transform, Boolean)
Returns an instanced copy of the given prefab object. If the pool is empty, a new object will be instantiated, otherwise a recycled object will be re-used.
Declaration
public T Instantiate<T>(T prefab, Transform parent, bool instantiateInWorldSpace)
where T : Component, IPoolable
Parameters
Type | Name | Description |
---|---|---|
T | prefab | Object prefab to make a copy of |
UnityEngine.Transform | parent | Parent that will be assigned to the new object |
System.Boolean | instantiateInWorldSpace | Pass true to maintain the world position of the Object, and false to set the Object's position relative to its new parent |
Returns
Type | Description |
---|---|
T | The instantiated/recycled clone |
Type Parameters
Name | Description |
---|---|
T | The object's prefab type |
Remarks
Awake/Start will not get called on recycled objects. Instead, use OnPoolInstantiate() for per-object startup code
Instantiate<T>(T, Vector3, Quaternion)
Returns an instanced copy of the given prefab object. If the pool is empty, a new object will be instantiated, otherwise a recycled object will be re-used.
Declaration
public T Instantiate<T>(T prefab, Vector3 position, Quaternion rotation)
where T : Component, IPoolable
Parameters
Type | Name | Description |
---|---|---|
T | prefab | Object prefab to make a copy of |
UnityEngine.Vector3 | position | Position of the new object |
UnityEngine.Quaternion | rotation | Orientation of the new object |
Returns
Type | Description |
---|---|
T | The instantiated/recycled clone |
Type Parameters
Name | Description |
---|---|
T | The object's prefab type |
Remarks
Awake/Start will not get called on recycled objects. Instead, use OnPoolInstantiate() for per-object startup code
Instantiate<T>(T, Vector3, Quaternion, Transform)
Returns an instanced copy of the given prefab object. If the pool is empty, a new object will be instantiated, otherwise a recycled object will be re-used.
Declaration
public T Instantiate<T>(T prefab, Vector3 position, Quaternion rotation, Transform parent)
where T : Component, IPoolable
Parameters
Type | Name | Description |
---|---|---|
T | prefab | Object prefab to make a copy of |
UnityEngine.Vector3 | position | Position of the new object |
UnityEngine.Quaternion | rotation | Orientation of the new object |
UnityEngine.Transform | parent | Parent that will be assigned to the new object |
Returns
Type | Description |
---|---|
T | The instantiated/recycled clone |
Type Parameters
Name | Description |
---|---|
T | The object's prefab type |
Remarks
Awake/Start will not get called on recycled objects. Instead, use OnPoolInstantiate() for per-object startup code
PreloadObjects<T>(T, Int32)
Instantiates a specified number of objects for the given prefab. This can help eliminate runtime performance hits by front-loading object creation (on level load, for instance).
Declaration
public void PreloadObjects<T>(T prefab, int count)
where T : Component
Parameters
Type | Name | Description |
---|---|---|
T | prefab | Object prefab to make copies of |
System.Int32 | count | Number of objects to instantiate |
Type Parameters
Name | Description |
---|---|
T | Type of prefab |