public void CreateBusLines() { if (busInfo == null) { Debug.Log("no busInfo loaded."); return; } TransLineCreator creator = TransLineCreator.AttachToGameObject(); creator.SetLines(GameObject.FindGameObjectsWithTag("TransLine")); creator.SetStations(FindObjectsOfType <StationController>()); // Go through the flows (bus lines) in busInfo. foreach (var flow in busInfo.flows) { creator.ResetEditingInfo(); creator.editLineName = flow.id; creator.lineCategory = LineCategory.Bus; foreach (var stop in flow.stops) { var go = GameObject.Find(stop.busStop); creator.AddStationToNewLine(go.GetComponentInParent <StationController>()); } // LATER TODO: Calculate the traveling time in Sumo based on maxSpeed and length of the edges. creator.CreateNewLine(); } DestroyImmediate(creator); }
static void EditLine() { AddModuleIfNotExist(transModuleName); TransLineCreator creator = TransLineCreator.AttachToGameObject(); Selection.activeGameObject = creator.gameObject; }
static void LoadStationsAndLines() { AddModuleIfNotExist(transModuleName); var path = EditorUtility.OpenFilePanel("Load XML Data", "Assets/Transportations", "xml"); if (path.Length == 0) { EditorUtility.DisplayDialog("Loading Cancelled", "No file was provided", "OK"); return; } ClearAll(); // Load stations and lines from xml. var container = TrafficContainer.Load(path); // Add stations from container to the scene. StationCreator stationCreator = StationCreator.AttachToGameObject(); stationCreator.SetStations(FindObjectsOfType <StationController>()); // the station might get a new id, therefor using a dictionary to // find the right stationController when creating line. Dictionary <int, StationController> idLookUp = new Dictionary <int, StationController>(); foreach (var s in container.stations) { var station = stationCreator.AddNewStation(s.GetPoint(), s.name); idLookUp.Add(s.id, station); } DestroyImmediate(stationCreator); // Add lines from container to the scene. TransLineCreator lineCreator = TransLineCreator.AttachToGameObject(); lineCreator.SetLines(GameObject.FindGameObjectsWithTag("TransLine")); foreach (var line in container.lines) { lineCreator.ResetEditingInfo(); lineCreator.editLineName = line.name; lineCreator.lineCategory = line.GetCategory(); foreach (var id in line.GetStationIds()) { var station = idLookUp[id]; lineCreator.AddStationToNewLine(station, line); } lineCreator.CreateNewLine(); } DestroyImmediate(lineCreator); string stationStats = string.Format("{0} stations loaded to the scene.", container.stations.Count); string lineStats = string.Format("{0} lines loaded to the scene.", container.lines.Count); EditorUtility.DisplayDialog("Loading Finished", stationStats + "\n" + lineStats, "OK"); }
public void CreateWalkingRoutes() { TransLineCreator lineCreator = TransLineCreator.AttachToGameObject(); lineCreator.SetLines(GameObject.FindGameObjectsWithTag("TransLine")); var stations = FindObjectsOfType <StationController>(); if (stations.Length < 1) { return; } float speed = 4; var globalParams = FindObjectOfType <FlashPedestriansGlobalParameters>(); if (globalParams != null) { speed = globalParams.averageSpeed; } for (int i = 0; i < stations.Length; i++) { for (int j = i + 1; j < stations.Length; j++) { var pos1 = stations[i].transform.position; var pos2 = stations[j].transform.position; var dist = Vector3.Distance(pos1, pos2); if (dist <= walkingDistance) { lineCreator.ResetEditingInfo(); lineCreator.editLineName = stations[i].stationName + "-" + stations[j].stationName; lineCreator.lineCategory = LineCategory.Walk; lineCreator.AddStationToNewLine(stations[i]); lineCreator.AddStationToNewLine(stations[j]); lineCreator.travelTimes[0] = dist / speed; lineCreator.CreateNewLine(); } } } DestroyImmediate(lineCreator); }