04 Missiles

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 from AssetList<Missile>. It automatically gathers all prefabs with a Missile 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 to Fire, which picks a random missile prefab from the list, uses ObjectPool.GetSharedComponentPool to get the ObjectPool<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.
  • Missile flies straight and explodes when it collides with something or takes damage.
    • Each Missile has a reference to a particular Explosion prefab so they can have different types. In this case, slow missiles have a larger explosion.
    • Each Missile could have its own Explosion 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 use ObjectPool.GetSharedComponentPool so that every Missile with a particular Explosion 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.
  • Explosion expands then contracts over time, uses Plysics.OverlapSphere to detect objects within its radius, and DamageSystem.DealDamage to try to hit them.
  • DamageSystem, IDealDamage, and ITakeDamage form a simple system which allows objects to pass damage messages around.