void Start() { network = new ERRoadNetwork(); network.BuildRoadNetwork(); customEasyRoads = new List <CustomEasyRoad>(); ProjectOnCamera2D projectOnCamera2D = car.GetComponent <ProjectOnCamera2D>(); projectOnCamera2D.cam = Camera.main; culture = CultureInfo.CreateSpecificCulture("en-US"); }
void FixedUpdate() { if (isGenerated) { if (!isPlaced) { this.PlaceCameraCar(); } // Wenn das Auto nicht selber fährt, dann das Fahren simulieren if (this.isSelfDriving) { SimulateCar(); } // Den ScreenRecorder aktivieren ScreenRecorder screenRecorder = Camera.main.GetComponent <ScreenRecorder>(); screenRecorder.isGenerated = true; // Wenn nicht vorhanden den filepath holen und die Datei erzeugen if (filePath == null) { this.filePath = Path.Combine(screenRecorder.captureFolder, coordFilename); if (!File.Exists(filePath)) { File.Create(filePath); } } if (screenRecorder.updateCounter == screenRecorder.takePictureEveryXFrame && screenRecorder.capture) { screenRecorder.TakePicture(); // Über alle Autos iterieren und die Koordinaten der sichtbaren speichern. //string textToAppend = "Picture " + this.imageCounter + ":"; string textToAppend = string.Empty; foreach (CustomEasyRoad ceRoad in customEasyRoads) { foreach (Tuple <GameObject, int> carOnLane in ceRoad.CarsOnLanes) { if (carOnLane == null) { continue; } ProjectOnCamera2D projectOnCamera2D = carOnLane.First.GetComponent <ProjectOnCamera2D>(); // Wenn das Auto auf dem Screen sichtbar ist, die Koordinaten speichern. if (projectOnCamera2D.IsVisible) { textToAppend += screenRecorder.counter + ":" + carOnLane.Second + "," + projectOnCamera2D .getRelativeBoxCoords() .Select(c => c.First.ToString("G", culture) + "," + c.Second.ToString("G", culture)) .Aggregate((a, b) => a + "," + b) + ";"; } else { textToAppend += screenRecorder.counter + ":"; } } } // Schreibe die Koordinaten in die Datei. new System.Threading.Thread(() => { using (StreamWriter writer = File.AppendText(filePath)) { writer.WriteLine(textToAppend); writer.Close(); } this.imageCounter++; }).Start(); } } }
void FixedUpdate() { if (isGenerated) { if (!isPlaced) { this.PlaceCameraCar(); } // Wenn das Auto nicht selber fährt, dann das Fahren simulieren if (this.isSelfDriving) { SimulateCar(); } // Den ScreenRecorder aktivieren ScreenRecorder screenRecorder = Camera.main.GetComponent <ScreenRecorder>(); screenRecorder.isGenerated = true; screenRecorder.updateCounter++; if (screenRecorder.updateCounter % screenRecorder.takePictureEveryXFrame == 0 && screenRecorder.capture) { // Über alle Autos iterieren und die Koordinaten der sichtbaren speichern. //string textToAppend = "Picture " + screenRecorder.counter + ":"; string textToAppend = string.Empty; List <Tuple <GameObject, int> > visibleCars = new List <Tuple <GameObject, int> >(); foreach (CustomEasyRoad ceRoad in customEasyRoads) { foreach (Tuple <GameObject, int> carOnLane in ceRoad.CarsOnLanes) { if (carOnLane == null || carOnLane.First == null) { continue; } ProjectOnCamera2D projectOnCamera2D = carOnLane.First.GetComponent <ProjectOnCamera2D>(); // Wenn das Auto auf dem Screen sichtbar ist, die Koordinaten speichern. if (projectOnCamera2D.IsVisible) { visibleCars.Add(carOnLane); } } } if (visibleCars.Count != 1) { return; } Tuple <GameObject, int> visibleCar = visibleCars.First(); textToAppend += visibleCar.Second + "," + visibleCar.First.GetComponent <ProjectOnCamera2D>() .getRelativeBoxCoords() .Select(c => c.First.ToString("G", culture) + "," + c.Second.ToString("G", culture)) .Aggregate((a, b) => a + "," + b) + ";"; screenRecorder.TakePicture(textToAppend); } DestroyColliderCars(); } }