// Use this for initialization void Start() { // Init Colors colors = new List <Color> { new Color(153f / 255f, 0f, 0f), new Color(51f / 255f, 102f / 255f, 0f), new Color(0f, 102f / 255f, 204f / 255f), new Color(1f, 1f, 1f), new Color(0f, 0f, 0f), new Color(77f / 255f, 77f / 255f, 77f / 255f), new Color(97f / 255f, 83f / 255f, 63f / 255f), new Color(1f, 1f, 102f / 255f), new Color(UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f)), new Color(UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f)), new Color(UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f)), new Color(UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f)) }; // Read paths from text files string sumoBinPath; if (sumoGUIEnabled) { sumoBinPath = System.IO.File.ReadAllText(Application.dataPath + "\\Resources\\sumoBinPath.dat") + "\\sumo-gui.exe"; } else { sumoBinPath = System.IO.File.ReadAllText(Application.dataPath + "\\Resources\\sumoBinPath.dat") + "\\sumo.exe"; } string mapNet = (System.IO.File.ReadAllText(Application.dataPath + "\\Resources\\sumoFilesPath.dat") + "\\map.net.xml").Replace("/", "\\"); string routeNet = (System.IO.File.ReadAllText(Application.dataPath + "\\Resources\\sumoFilesPath.dat") + "\\map.rou.xml").Replace("/", "\\"); // Other vehicles vehiclesInScene = new List <GameObject>(); vehicles = new Dictionary <string, SUMOCombinedPositionOrientation>(); vehicles3D = new Dictionary <string, GameObject>(); conn = new SumoTraciConnection(sumoBinPath, mapNet, routeNet); conn.AddOption("step-length", stepLengthSeconds + ""); conn.AddOption("start", ""); // start sumo immediately conn.AddOption("quit-on-end", ""); // stop sumo immediately after unity3D stopped // start Traci Server conn.RunServer(remoteIpAddress, Convert.ToInt32(this.remotePort)); if (enableEgoVehicle) { // Insert ego vehicle // Get random route for being able to insert the ego vehicle (A new vehicle must have a route assigned) SumoStringList routes = (SumoStringList)conn.Do_job_get(Route.GetIDList()); conn.Do_job_set(Vehicle.Add("egoVehicle", "DEFAULT_VEHTYPE", routes.Get(0), 0, 0, 0, (byte)0)); conn.Do_job_set(Vehicle.SetColor("egoVehicle", new SumoColor(127, 0, 0, 127))); } // Find all traffic lights trafficLights3D = new Dictionary <string, GameObject>(); SumoStringList trafficLights = (SumoStringList)conn.Do_job_get(Trafficlights.GetIDList()); foreach (string s in trafficLights.getList()) { var objects = Resources.FindObjectsOfTypeAll <GameObject>().Where(obj => obj.name.Equals("TrafficLight_" + s)); foreach (GameObject g in objects) { trafficLights3D.Add(s + g.transform.Find("index").GetChild(0).name, g); } } // Timer for Realtime-Simulation unity3DstartTime = Stopwatch.StartNew(); // Timer for traffic lights update (No need to do this every sim step) trafficLightsUpdate = Stopwatch.StartNew(); // Timer for watchdog watchdog = new Stopwatch(); }