/// <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>(); }
/// <summary> /// Spawn a set of instances retrieved from the pool /// </summary> public void SpawnSet() { for (int i = 0; i < m_nObjectsToSpwan; i++) { var clone = PoolManager.SpawnObject(m_prefabToSpawn); var entity = clone.GetComponent <EntityBehaviour>(); entity.Spawn(); BasicCollisionDectection collisionDetection = entity.GetComponentInChildren <BasicCollisionDectection>(); if (collisionDetection != null) { collisionDetection.UnitShot += (s, e) => OnShot(s, e); } // Suscribe to collision events entity.Collided += (s, e) => { m_spawnObjects.Remove(entity); }; // Refactor! var passiveEnemy = clone.GetComponent <PassiveEnemy>(); if (passiveEnemy != null) { passiveEnemy.AsteroidShatter += OnAsteroidShatter; } m_spawnObjects.Add(entity); } }
public void Initialize() { // All dynamic objects nested in the Dynamic GO Transform parent = GameObject.FindGameObjectWithTag(Tags.Dynamic).transform; // Player player = Player.Spawn(m_playerShipPrefab, parent); m_playerCollisionDetection = player.GetComponentInChildren <BasicCollisionDectection>(); //m_playerCollisionDetection = player.GetComponentInChildren<PlayerCollisionDetection>(); AddListeners(); player.Destruction(); // Pool of asteroids PoolManager.BuildPool(m_asteroidBigPrefab, UNITS_POOL_SIZE); m_asteroidBigPool = PoolManager.GetPool(m_asteroidBigPrefab); PoolManager.BuildPool(m_asteroidSmallPrefab, UNITS_POOL_SIZE); m_asteroidSmallPool = PoolManager.GetPool(m_asteroidSmallPrefab); //m_asteroidBigPool = ObjectPool.Build(m_asteroidBigPrefab, 25); //m_asteroidSmallPool = ObjectPool.Build(m_asteroidSmallPrefab, 25); // Pool of explosions detonator.BuildPools(FX_POOL_SIZE); }
public void Reset() { StopSpawn = true; EnemyUnit currentEnemy; for (int i = 0; i < m_spawnEnemies.Count; i++) { currentEnemy = m_spawnEnemies[i]; BasicCollisionDectection collisionDetection = currentEnemy.GetComponentInChildren <BasicCollisionDectection>(); if (collisionDetection != null) { collisionDetection.UnitShot -= (s, e) => OnShot(s, e); } currentEnemy.Destruction(); } m_spawnEnemies = new List <ActiveEnemyUnit>(); }
public IEnumerator StartSpawner(Transform target) { if (stopSpawn) { yield return(null); } // Wait to Start Spawning yield return(new WaitForSeconds(startWaitTs)); m_currentEnemy = UnityEngine.Random.Range(0, m_enemyPrefabToSpawn.Length); m_currentEnemy = 0; var enemyClone = PoolManager.SpawnObject(m_enemyPrefabToSpawn[m_currentEnemy]); var activeEnemyUnity = enemyClone.GetComponent <ActiveEnemyUnit>(); // Suscribe to Enemy Collision Events - When is Shot BasicCollisionDectection collisionDetection = activeEnemyUnity.GetComponentInChildren <BasicCollisionDectection>(); if (collisionDetection != null) { collisionDetection.UnitShot += (s, e) => OnShot(s, e); } // Suscribe to Enemy Collision Events - When is Collided activeEnemyUnity.Collided += (s, e) => { m_spawnEnemies.Remove(activeEnemyUnity); }; if (m_spawnEnemies == null) { m_spawnEnemies = new List <ActiveEnemyUnit>(); } m_spawnEnemies.Add(activeEnemyUnity); // Spawn at free position activeEnemyUnity.Spawn(); // Start movement ICustomMove customMove = activeEnemyUnity.GetComponent <ICustomMove>(); customMove.Move(target); //activeEnemyUnity.Move(target); }
private void OnAsteroidShatter(object sender, EventArgs e) { PassiveEnemy passiveEnemy = sender as PassiveEnemy; passiveEnemy.AsteroidShatter -= OnAsteroidShatter; for (int i = 0; i < passiveEnemy.NumBits; i++) { var clone = PoolManager.SpawnObject(m_childPrefabToSpawn); var entity = clone.GetComponent <EntityBehaviour>(); entity.SpawnAt(passiveEnemy.transform.position); m_spawnObjects.Add(entity); BasicCollisionDectection collisionDetection = entity.GetComponentInChildren <BasicCollisionDectection>(); if (collisionDetection != null) { collisionDetection.UnitShot += (s, evt) => OnShot(s, evt); } // Suscribe to collision events entity.Collided += (s, evt) => { m_spawnObjects.Remove(entity); }; } }