This example scene is located in Assets/Plugins/Weaver/Examples/04 Missiles. Demonstrates an Asset List which automatically gathers all prefabs in a folder in conjunction with Object Pooling at runtime.
- Assets/Plugins/Weaver/Examples/04 Missiles/Missiles.asset is an Asset List. Specifically, a
MissileList
which inherits fromAssetList<Missile>
. It automatically gathers all prefabs with aMissile
component in the target folder when entering play mode or compiling a runtime build so they can be accessed efficiently as a simple list at runtime. MissileRain
has various parameters that determine how often it will fire and how fast the missiles it fires will be travelling.FixedUpdate
determines when toFire
, which picks a random missile prefab from the list, usesObjectPool.GetSharedComponentPool
to get theObjectPool<Missile>
that manages instances of that particular prefab, and launches an instance from that pool.- It can't just use a single
ObjectPool<Missile>
for all its missiles because the ones spawned by each prefab are different, so each prefab needs its own pool. - This also means that anything else firing instances of the same prefab could use the same pool.
- It can't just use a single
Missile
flies straight and explodes when it collides with something or takes damage.- Each
Missile
has a reference to a particularExplosion
prefab so they can have different types. In this case, slow missiles have a larger explosion. - Each
Missile
could have its ownExplosion
instance, but since only one or the other will be active at any given time that would allocate more objects than necessary. Instead, they also useObjectPool.GetSharedComponentPool
so that everyMissile
with a particularExplosion
prefab will share the same pool for it. Specifically, every instance of the Large Missile.prefab will use the same pool of the Large Explosion.prefab and since Slow Missile.prefab also uses the same explosion it will share the same pool as well.
- Each
Explosion
expands then contracts over time, usesPlysics.OverlapSphere
to detect objects within its radius, andDamageSystem.DealDamage
to try to hit them.DamageSystem
,IDealDamage
, andITakeDamage
form a simple system which allows objects to pass damage messages around.