|
@@ -29,50 +29,75 @@ namespace TrafficSimulation{
|
|
|
void OnDestroy() {
|
|
|
StopSpawning();
|
|
|
}
|
|
|
+ /// <summary>
|
|
|
+ /// Use this method to active the spawner
|
|
|
+ /// </summary>
|
|
|
public void StartSpawner(){
|
|
|
- Debug.Log("Start Spawner");
|
|
|
this.isActive = true;
|
|
|
StartSpawns();
|
|
|
}
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Use this method to deactive the spawner
|
|
|
+ /// </summary>
|
|
|
public void StopSpawner(){
|
|
|
this.isActive = false;
|
|
|
StopSpawning();
|
|
|
DespawnAllCars();
|
|
|
}
|
|
|
+ /// <summary>
|
|
|
+ /// Check every set despawn area if cars have to be despawned
|
|
|
+ /// </summary>
|
|
|
private void CheckDespawns(){
|
|
|
- Debug.Log("Check for despawn");
|
|
|
foreach(PresetTrigger despawn in despawns){
|
|
|
if(despawn.checkLastTrigger()){
|
|
|
DespawnCar(despawn.getLastCollider());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ /// <summary>
|
|
|
+ /// Start a coroutine to spawn cars at every given spawn point
|
|
|
+ /// </summary>
|
|
|
private void StartSpawns(){
|
|
|
- Debug.Log("Start Spawns");
|
|
|
foreach(Transform spawnPos in spawns){
|
|
|
IEnumerator coroutine = AutoSpawning(spawnPos);
|
|
|
this.coroutines.Add(coroutine);
|
|
|
StartCoroutine(coroutine);
|
|
|
}
|
|
|
}
|
|
|
+ /// <summary>
|
|
|
+ /// Despawn all cars used from this spawner since it was active
|
|
|
+ /// </summary>
|
|
|
private void DespawnAllCars(){
|
|
|
- foreach(GameObject car in this.cars){
|
|
|
- DespawnCar(car);
|
|
|
- }
|
|
|
+ this.cars.ForEach(car => DespawnCar(car));
|
|
|
}
|
|
|
+ /// <summary>
|
|
|
+ /// Stop all coroutines
|
|
|
+ /// </summary>
|
|
|
private void StopSpawning(){
|
|
|
foreach(IEnumerator coroutine in this.coroutines){
|
|
|
StopCoroutine(coroutine);
|
|
|
}
|
|
|
}
|
|
|
+ /// <summary>
|
|
|
+ /// Spawn a car on the given transform
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="carSpawn">Transform</param>
|
|
|
void SpawnCar(Transform carSpawn){
|
|
|
- Debug.Log("despawnCars");
|
|
|
this.cars.Add(this.carPool.SpawnCar(carSpawn));
|
|
|
}
|
|
|
+ /// <summary>
|
|
|
+ /// Despawn the given car
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="car">GameObject</param>
|
|
|
void DespawnCar(GameObject car){
|
|
|
- Debug.Log("despawnCars");
|
|
|
this.carPool.despawnCar(car);
|
|
|
}
|
|
|
+ /// <summary>
|
|
|
+ /// IEnumerator for the coroutine which spawns a car at the given position in the set spawnRate
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="position">Transform</param>
|
|
|
+ /// <returns></returns>
|
|
|
public IEnumerator AutoSpawning(Transform position){
|
|
|
while(true){
|
|
|
SpawnCar(position);
|