Example #1
0
        /// <summary>
        /// Reset the list which track the active Units
        /// Recycle the instances back to the pool
        /// </summary>
        public void Reset()
        {
            if (m_spawnObjects != null)
            {
                int nItems = m_spawnObjects.Count;

                for (int i = m_spawnObjects.Count - 1; i >= 0; i--)
                {
                    EntityBehaviour          entity             = m_spawnObjects[i];
                    BasicCollisionDectection collisionDetection = entity.GetComponentInChildren <BasicCollisionDectection>();

                    //	Unsuscribe to events
                    if (collisionDetection != null)
                    {
                        collisionDetection.UnitShot -= (s, e) => OnShot(s, e);
                    }

                    entity.Collided -= (s, e) => { m_spawnObjects.Remove(entity); };

                    //	Destroy
                    entity.Destruction();
                }
            }
            //	Clear the active list
            m_spawnObjects = new List <EntityBehaviour>();
        }
        //	Player Shot

        /*public event EventHandler<CollisionDetectedEventArgs> PlayerShot;
         * protected virtual void OnPlayerShot(object sender, CollisionDetectedEventArgs e)
         * {
         *      if (PlayerShot != null)
         *              PlayerShot(this, e);
         * }*/

        //	Active or Passive Enemy (Asteroids/Saucer) gets shot
        void OnTriggerEnter(Collider trigger)
        {
            IShootable ammu = trigger.gameObject.GetComponent <IShootable>();

            //	Ignore if is not a shot
            if (ammu == null)
            {
                return;
            }

            Transform       ammuSource   = ammu.Source;
            EntityBehaviour sourceEntity = ammuSource.gameObject.GetComponentInParent <EntityBehaviour>();
            EnemyUnit       targetUnit   = gameObject.GetComponentInParent <EnemyUnit>();

            if (targetUnit != null && sourceEntity != null)
            {
                /*if (targetUnit.tag == "Saucer")
                 *      Debug.Log("STOP");
                 *
                 * if (targetUnit.tag == "Player")
                 *      Debug.Log("PLAYER SHOT");
                 */

                // Unit Shot by Player (Asteroid or Saucer)
                CollisionDetectedEventArgs colisionEvent = new CollisionDetectedEventArgs();
                colisionEvent.SourceEntity = sourceEntity;                      //	Player
                colisionEvent.EnemyUnit    = targetUnit;                        //	Enemy Shot - Asteroid/Saucer

                //	Debug.Log(this.name + " -Trigger in " + trigger.gameObject.name);
                OnUnitShot(this, colisionEvent);
            }
        }