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 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); }
public override void OnInspectorGUI() { GUI.color = Color.gray; DrawDefaultInspector(); creator = target as TransLineCreator; GUILayout.Space(5); if (editing || creating) { if (creating) { GUI.color = Color.white; GUILayout.Label("Enter the name of the new line"); creator.editLineName = GUILayout.TextField(creator.editLineName); creator.lineCategory = (LineCategory)EditorGUILayout.EnumPopup("Line Category:", creator.lineCategory); GUILayout.Space(5); GUI.color = Color.green; GUILayout.Label("Add a station by clicking on one..."); GUILayout.Space(5); GUI.color = Color.white; StationsEditor(); if (creator.editingLineStations.Count > 1) { GUILayout.FlexibleSpace(); GUI.color = Color.green; if (GUILayout.Button("Create")) { creator.CreateNewLine(); creator.ResetEditingInfo(); creating = false; } } GUILayout.FlexibleSpace(); GUI.color = Color.yellow; if (GUILayout.Button("Back")) { creator.ResetEditingInfo(); creating = false; } } if (editing) { GUI.color = Color.white; if (creator.editingLine == null) { GUILayout.Space(10); GUILayout.Label("Lines in this scene:"); foreach (var line in creator.lines.Values) { GUI.backgroundColor = line.lineColor; if (GUILayout.Button(line.lineName)) { creator.editingLine = line; creator.PrepareLineForEdit(line); } } GUILayout.FlexibleSpace(); GUI.color = Color.yellow; GUI.backgroundColor = Color.yellow; if (GUILayout.Button("Back")) { creator.ResetEditingInfo(); editing = false; } } else { GUI.color = Color.white; GUILayout.Label("Enter the name of the new line"); creator.editLineName = GUILayout.TextField(creator.editLineName); creator.lineCategory = (LineCategory)EditorGUILayout.EnumPopup("Line Category:", creator.lineCategory); GUILayout.Space(10); GUILayout.Label("Stations in this line:"); StationsEditor(); GUILayout.FlexibleSpace(); GUI.color = Color.cyan; if (GUILayout.Button("Update Line")) { creator.SaveEditingLine(); creator.ResetEditingInfo(); } GUILayout.Space(10); GUI.color = Color.red; if (GUILayout.Button("Remove this line")) { creator.RemoveEditLine(); creator.ResetEditingInfo(); //editing = false; } GUILayout.FlexibleSpace(); GUI.color = Color.yellow; if (GUILayout.Button("Back")) { creator.ResetEditingInfo(); } } } } else { WalkingDistanceEditor(); GUI.color = Color.white; GUILayout.Label("Choose one of the alternatives to start:"); GUI.color = Color.green; if (GUILayout.Button("Create new line")) { creator.ResetEditingInfo(); creating = true; } GUILayout.Space(10); GUI.color = Color.cyan; if (GUILayout.Button("Edit existing line")) { creator.ResetEditingInfo(); editing = true; } GUILayout.FlexibleSpace(); GUI.color = Color.white; GUILayout.Label("Press this button to exit 'Transportation Line Creator'"); GUI.color = Color.yellow; if (GUILayout.Button("Exit")) { editing = false; DestroyImmediate(creator); } } }