IEnumerator SpawnEnemiesInRounds() { RoundState = E_RoundState.E_SPAWNING_ENEMIES; for (int i = 0; i < SpawnRounds.Length; i++) { RoundInfo round = SpawnRounds[i]; float delay = round.SpawnDelay; while (delay > 0) { if (EnemiesAlive.Count == 0 || EnemiesAlive.Count <= round.MinEnemiesFomLastRound) { break; } yield return(new WaitForSeconds(0.5f)); delay -= 0.5f; } for (int ii = 0; ii < round.Spawns.Length; ii++) { RoundInfo.SpawnInfo spawnInfo = round.Spawns[ii]; yield return(new WaitForSeconds(spawnInfo.SpawnDelay)); SpawnPointEnemy spawnpoint = GetAvailableSpawnPoint(spawnInfo.SpawnPoint == null || spawnInfo.SpawnPoint.Length == 0 ? SpawnPoints : spawnInfo.SpawnPoint); if (spawnInfo.RotateToPlayer) { Vector3 dir = Player.Instance.Agent.Position - spawnpoint.Transform.position; dir.Normalize(); spawnpoint.Transform.forward = dir; } GameObject enemy = Mission.Instance.GetHuman(spawnInfo.EnemyType, spawnpoint.Transform); while (enemy == null) { yield return(new WaitForSeconds(0.2f)); enemy = Mission.Instance.GetHuman(spawnInfo.EnemyType, spawnpoint.Transform); } CombatEffectsManager.Instance.PlaySpawnEffect(spawnpoint.Transform.position, spawnpoint.Transform.forward); Agent agent = enemy.GetComponent("Agent") as Agent; agent.PrepareForStart(); Mission.Instance.CurrentGameZone.AddEnemy(agent); EnemiesAlive.Add(agent); yield return(new WaitForSeconds(0.1f)); } } RoundState = E_RoundState.E_IN_PROGRESS; }
IEnumerator SpawnEnemiesInRounds() { State = E_State.E_SPAWNING_ENEMIES; Agent ImportantAgent = null; for (int i = 0; i < SpawnRounds.Length; i++) { RoundInfo round = SpawnRounds[i]; float delay = round.SpawnDelay; while (delay > 0) { // 重要的boss杀死后,就直接结束产怪(一般是Boss) if (ImportantAgent != null && ImportantAgent.IsAlive == false) { State = E_State.E_IN_PROGRESS; yield break; } if (EnemiesAlive.Count == 0 || EnemiesAlive.Count <= round.MinEnemiesFomLastRound) { break; // dont wait, when enemies are killed or less then required } yield return(new WaitForSeconds(0.5f)); delay -= 0.5f; } for (int j = 0; j < round.Spawns.Length; j++) { RoundInfo.SpawnInfo spawnInfo = round.Spawns[j]; yield return(new WaitForSeconds(spawnInfo.SpawnDelay)); SpawnPointEnemy spawnpoint = GetAvailableSpawnPoint(spawnInfo.SpawnPoint == null || spawnInfo.SpawnPoint.Length == 0 ? SpawnPoints : spawnInfo.SpawnPoint); // 如果怪出生朝向玩家,就调整出生方位 if (spawnInfo.RotateToPlayer) { Vector3 dir = Player.Instance.transform.position - spawnpoint.Transform.position; dir.Normalize(); spawnpoint.Transform.forward = dir; } Agent enemy = GenerateEnemyOnType(spawnInfo.EnemyType, spawnpoint.Transform); while (enemy == null) { yield return(new WaitForSeconds(0.2f)); enemy = GenerateEnemyOnType(spawnInfo.EnemyType, spawnpoint.Transform); } CombatEffectsManager.Instance.PlaySpawnEffect(spawnpoint.Transform.position, spawnpoint.Transform.forward); enemy.PrepareForStart(); enemy.SoundPlaySpawn(); if (RootEnemy != null) { enemy.transform.SetParent(RootEnemy.transform); } EnemiesAlive.Add(enemy); if (spawnInfo.WhenKilledStopSpawn) { ImportantAgent = enemy; } yield return(new WaitForSeconds(0.1f)); } } State = E_State.E_IN_PROGRESS; }
IEnumerator CreateEnemy(SpwanPointEnemy point, E_EnemyType enemyType = E_EnemyType.None, RoundInfo.SpawnInfo spawnInfo = null) { if (enemyType == E_EnemyType.None) { enemyType = point.EnemyType; } //从缓存获取怪物 //GameObject prefab = Resources.Load<GameObject> ("Prefabs/Monster"); //Agent enemy = GameObject.Instantiate (prefab).GetComponent<Agent> (); Agent enemy = MissionZone.Instance.GetHuman(enemyType, point.transform); while (enemy == null) { yield return(new WaitForSeconds(0.5f)); enemy = MissionZone.Instance.GetHuman(enemyType, point.transform); } enemy.PrepareForStart(); CombatEffectsManager.Instance.PlaySpawnEffect(point.Transform.position, point.Transform.forward); MyGameZone.AddEnemy(enemy); EnemiesAlive.Add(enemy); if (spawnInfo != null && spawnInfo.WhenKilledStopSpawn) { ImportantAgent = enemy; } yield return(new WaitForSeconds(0.1f)); }
IEnumerator SpawnEnemysInRounds() { State = E_State.SpawnEnemys; ImportantAgent = null; for (int i = 0; i < SpawnRounds.Length; i++) { RoundInfo round = SpawnRounds [i]; float delay = round.SpawnDelay; //波次延时 while (delay > 0) { if (ImportantAgent != null && ImportantAgent.IsAlive == false) { State = E_State.WaitAllDead; yield break; } if (EnemiesAlive.Count == 0 || EnemiesAlive.Count <= round.MinEnemiesFomLastRound) { break; } yield return(new WaitForSeconds(0.5f)); delay -= 0.5f; } //开始该波次出怪 for (int ii = 0; ii < round.Spawns.Length; ii++) { RoundInfo.SpawnInfo spawnInfo = round.Spawns [ii]; //出怪延时 yield return(new WaitForSeconds(spawnInfo.SpwanDelay)); SpwanPointEnemy[] temp; if (spawnInfo.SpwanPoint != null && spawnInfo.SpwanPoint.Length > 0) { temp = spawnInfo.SpwanPoint; } else { temp = SpwanPoints; } //选择出怪最佳位置 SpwanPointEnemy point = GetAvailableSpawnPoint(temp); //SpwanPointEnemy point = temp [0]; //改变出生点的方向即改变怪物的朝向 if (spawnInfo.RotateToPlayer == true) { Vector3 playerPos = Player.Instance.Agent.Position; Vector3 dir = playerPos - point.transform.position; dir.Normalize(); point.transform.forward = dir; } //开场动画 //yield return new WaitForSeconds (0.5f); yield return(CreateEnemy(point, spawnInfo.EnemyType)); yield return(new WaitForSeconds(1f)); } } State = E_State.WaitAllDead; }