IEnumerator DispatchSoliders() { for (int i = 0; i < 5; i++) { GameObject soliderObject = poolObjectFactory.AcquireObject(Random.insideUnitCircle * 3, templateObject: solider); soliderObject.GetComponent <CharacterMono>().characterModel.unitFaction = i % 2 == 0? UnitFaction.Blue : UnitFaction.Red; // 触发产生对象的事件 if (OnCreateNPCGameObject != null) { OnCreateNPCGameObject(Vector3.zero, soliderObject, poolObjectFactory); } yield return(new WaitForSeconds(5f)); } }
//=========================== // 出兵 IEnumerator DispatchSoliders() { yield return(new WaitForSeconds(2)); while (!isGameOver) { int a = 0; // 遍历每个出兵点,进行出兵 foreach (var p in placesOfDispatchRed) { // 对每个出兵点产生一群单位 foreach (var solider in solidersPrefabs) { Vector3 position = (p + UnityEngine.Random.insideUnitSphere * 3); // 从对象池中取出对象 GameObject soliderObject = poolObjectFactory.AcquireObject(position, templateObject: solider); // 设置该单位的阵营 soliderObject.GetComponent <CharacterMono>().characterModel.unitFaction = UnitFaction.Red; // 触发产生对象的事件 if (OnCreateNPCGameObject != null) { OnCreateNPCGameObject(position, soliderObject, poolObjectFactory); } if (a == 0) { soliderObject.GetComponent <CharacterMono>().wayPointsUnit = new WayPointsUnit(WayPointEnum.UpRoad, UnitFaction.Red); } else if (a == 1) { soliderObject.GetComponent <CharacterMono>().wayPointsUnit = new WayPointsUnit(WayPointEnum.MiddleRoad, UnitFaction.Red); } else if (a == 2) { soliderObject.GetComponent <CharacterMono>().wayPointsUnit = new WayPointsUnit(WayPointEnum.DownRoad, UnitFaction.Red); } // 设置战争迷雾 FogSystem.Instace.AddFOVUnit(soliderObject.GetComponent <CharacterMono>()); } a++; } int b = 0; foreach (var p in placesOfDispatchBlue) { // 对每个出兵点产生一群单位 foreach (var solider in solidersPrefabs) { Vector3 position = (p + UnityEngine.Random.insideUnitSphere * 3); GameObject soliderObject = poolObjectFactory.AcquireObject(position, templateObject: solider); // 设置该单位的阵营 soliderObject.GetComponent <CharacterMono>().characterModel.unitFaction = UnitFaction.Blue; // 触发产生对象的事件 if (OnCreateNPCGameObject != null) { OnCreateNPCGameObject(position, soliderObject, poolObjectFactory); } if (b == 0) { soliderObject.GetComponent <CharacterMono>().wayPointsUnit = new WayPointsUnit(WayPointEnum.UpRoad, UnitFaction.Blue); } else if (b == 1) { soliderObject.GetComponent <CharacterMono>().wayPointsUnit = new WayPointsUnit(WayPointEnum.MiddleRoad, UnitFaction.Blue); } else if (b == 2) { soliderObject.GetComponent <CharacterMono>().wayPointsUnit = new WayPointsUnit(WayPointEnum.DownRoad, UnitFaction.Blue); } // 设置战争迷雾 FogSystem.Instace.AddFOVUnit(soliderObject.GetComponent <CharacterMono>()); } b++; } // 等待一段时间重新出兵 yield return(new WaitForSeconds(deltaTime)); } }