Maintain the instances created from the prefabs, for reusing in the current scene.
More...
|
static void | Allocate< T > (T prefab, int minTotal=0, int minSpare=0, int maxTotal=int.MaxValue, int maxSpare=int.MaxValue) |
| Adjust the count of spare instances created from the prefab. More...
|
|
static void | Allocate (GameObject prefab, int minTotal, int minSpare, int maxTotal, int maxSpare) |
| Adjust the count of spare instances created from the prefab. More...
|
|
static T | Require< T > (T prefab, Transform parent=null, Vector3 position=default, Vector3 rotation=default, bool active=true) |
| Get an instance created from the prefab. More...
|
|
static GameObject | Require (GameObject prefab, Transform parent, Vector3 position, Vector3 rotation, bool active) |
| Get an instance created from the prefab. More...
|
|
static bool | Release< T > (T instance, bool destroy=false) |
| Put the instance back to the pool. More...
|
|
static bool | Release (GameObject instance, bool destroy) |
| Put the instance back to the pool. More...
|
|
Maintain the instances created from the prefabs, for reusing in the current scene.
About resetting instances:
- It's hard to determine if any of an instance's component states has been changed.
- This'll clean up any new component attached after required out from the pool.
- You may use dynamic component,
OnDisable()
, or IPoolee
, to reset dynamic content.
- By the way, it's recommended not to use complex structure prefabs.
The instance life cycle from Require()
to Release()
:
- Move out from the pool hierarchy.
- Invoke
IPoolee.OnRequireFromPool()
of all components.
- Activate the
UnityEngine.GameObject
if need.
- Using phase.
- Deactivate the
UnityEngine.GameObject
.
- Invoke
IPoolee.OnReleaseIntoPool()
of all components.
- Clean up dynamic components.
- Move into the pool hierarchy.
static void Allocate< T > |
( |
T |
prefab, |
|
|
int |
minTotal = 0 , |
|
|
int |
minSpare = 0 , |
|
|
int |
maxTotal = int.MaxValue , |
|
|
int |
maxSpare = int.MaxValue |
|
) |
| |
|
static |
Adjust the count of spare instances created from the prefab.
- Template Parameters
-
T | The component or interface type. |
- Parameters
-
prefab | Prefab. |
minTotal | Minimum total count. |
minSpare | Minimum spare count. |
maxTotal | Maximum total count. |
maxSpare | Maximum spare count. |
static void Allocate |
( |
GameObject |
prefab, |
|
|
int |
minTotal, |
|
|
int |
minSpare, |
|
|
int |
maxTotal, |
|
|
int |
maxSpare |
|
) |
| |
|
static |
Adjust the count of spare instances created from the prefab.
- Parameters
-
prefab | Prefab. |
minTotal | Minimum total count. |
minSpare | Minimum spare count. |
maxTotal | Maximum total count. |
maxSpare | Maximum spare count. |
static T Require< T > |
( |
T |
prefab, |
|
|
Transform |
parent = null , |
|
|
Vector3 |
position = default , |
|
|
Vector3 |
rotation = default , |
|
|
bool |
active = true |
|
) |
| |
|
static |
Get an instance created from the prefab.
- Template Parameters
-
T | The component or interface type. |
- Parameters
-
prefab | Prefab. |
parent | Hierarchy parent. |
position | Local position. |
rotation | Local rotation. |
active | If to set the instance active. |
- Returns
- The instance.
static GameObject Require |
( |
GameObject |
prefab, |
|
|
Transform |
parent, |
|
|
Vector3 |
position, |
|
|
Vector3 |
rotation, |
|
|
bool |
active |
|
) |
| |
|
static |
Get an instance created from the prefab.
- Parameters
-
prefab | Prefab. |
parent | Hierarchy parent. |
position | Local position. |
rotation | Local rotation. |
active | If to set the instance active. |
- Returns
- The instance.
static bool Release< T > |
( |
T |
instance, |
|
|
bool |
destroy = false |
|
) |
| |
|
static |
Put the instance back to the pool.
- Template Parameters
-
T | The component or interface type. |
- Parameters
-
instance | Instance. |
destroy | If to destroy the instance if isn't from the pool. |
- Returns
true
if the instance is from the pool and released.
static bool Release |
( |
GameObject |
instance, |
|
|
bool |
destroy |
|
) |
| |
|
static |
Put the instance back to the pool.
- Parameters
-
instance | Instance. |
destroy | If to destroy the instance if isn't from the pool. |
- Returns
true
if the instance is from the pool and released.