[Base Class](../groups/Extension.Base Class.md) / ObjPool
ObjPool<T> Class
Universal object pool, which can be used for reuse of various types of objects
Example usage: Create a script called ObjPoolExample, place it in the object bar, open the script, modify the original content to the following, save and run the game, press the F key to generate a block based on the existing blocks in the object pool at the player's current position, and recycle the coordinates back to the origin after 5 seconds. Frequent F presses will prompt the client log that there are no objects in the object pool, and press the G key to destroy all blocks in the recycling state
Type parameters
Name |
---|
T |
Table of contents
Accessors
size(): number other |
---|
Get the number of free objects in the object pool |
Methods
clear(): void other |
---|
Clear objects from the pool |
despawn(obj : T ): void other |
Return an object |
spawn(): T other |
Generate an object |
Construct an object pool
Type parameters
Name |
---|
T |
Parameters
onCreateObj () => T | Callback for creating a new object |
---|---|
onReset? (obj : T ) => void | Reset object callback default: null |
onDestroy? (obj : T ) => void | Cancel object callback default: null |
onDespawn? (obj : T ) => void | Return object callback default: null |
initNum? number | The number of default cache objects default: 2 range: unlimited type: integer |
Accessors
size
• |
---|
Get the number of free objects in the object pool Returns |
number |
---|
Methods
clear
• clear(): void
other
Clear objects from the pool
despawn
• despawn(obj
): void
other
Return an object
Parameters
obj T | object |
---|
spawn
• spawn(): T
other
Generate an object
Returns
T | object |
---|