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
MissileListwhich inherits fromAssetList<Missile>. It automatically gathers all prefabs with aMissilecomponent 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. MissileRainhas various parameters that determine how often it will fire and how fast the missiles it fires will be travelling.FixedUpdatedetermines when toFire, which picks a random missile prefab from the list, usesObjectPool.GetSharedComponentPoolto 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
Missileflies straight and explodes when it collides with something or takes damage.- Each
Missilehas a reference to a particularExplosionprefab so they can have different types. In this case, slow missiles have a larger explosion. - Each
Missilecould have its ownExplosioninstance, 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.GetSharedComponentPoolso that everyMissilewith a particularExplosionprefab 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
Explosionexpands then contracts over time, usesPlysics.OverlapSphereto detect objects within its radius, andDamageSystem.DealDamageto try to hit them.DamageSystem,IDealDamage, andITakeDamageform a simple system which allows objects to pass damage messages around.