Getting Started
To use AutoPool for your project, you'll need to place the AP_Manager script on an object in your scene. This will become the root object of all your object pools. You can place and configure pools manually, or choose to create them on-the-fly during runtime. An AP_Pool script will appear for each pool, and have various options governing the behavior of its pool. Prefab: The prefab of the item this pool contains. Size: The number of items created when the scene starts. Empty Behavior: How the pool behaves when the pool is empty and a spawn is requested.
Max Size: The maximum number of items that can be added by Grow using spawn requests. Max Empty Behavior: How the pool behaves when the pool is empty, and is at the Max Size, and a spawn is requested.
See the tutorials for more information. Example Demo Scene
The initial set-up contains a GameObject called "Object Pools" with the AP_Manager script. The manager has one object pool already created. Attached to the Area object is a spawner that uses the above pool, and will spawn blue spheres. The spheres also have a spawner to create cubes, but there is no accompanying object pool. The cube pool will be created at runtime, and its size will be adjusted by the number of spheres created in the scene. Notice that the different colored cubes are all the same prefab, but are operating to selectively to only display one version for any given spawn. Scene Controls Use‘ p’ to pause or unpause the game. ‘f’ will play a single frame with every press. ‘[‘ will halve the game speed. ‘]’ will double the game speed. AP_DemoSpawn A simple script to spawn objects. Designate a prefab matching an object pool, and the time interval to request spawns, along with velocity and and a randomized angle. If randomChild is checked, the spawner will enable one of the child objects upon spawn. This is specifically for objects that are set up as multi-objects, such as the cube prefab. For pools created at runtime, specify the minimum pool items for the pool to contain. Once the minimum is reached use Add To Pool to create additional items, for each other spawner using that pool. AP_DemoDeathTimer A script to despawn units after a set amount of time. Also includes some simple visual changes. The cube is set up to contain multiple color versions. These are all disabled, and will be selectively enabled by the spawner script to simulate different objects. In the begining state the Blast object will be disabled and the object will be enabled. Once Death Time is reached the object parts are disabled and the blast part becomes enabled until the additional Despawn Time passes, at which time the object will return to the pool. |
Script Reference
In most cases, these scripts will be added to the appropriate objects automatically, but some efficiency can be realized by placing them manually ahead of time.
|