public void CreateBusStops() { if (busInfo == null) { Debug.Log("no busInfo loaded."); return; } if (netInfo == null) { Debug.Log("no netInfo loaded."); return; } var mb = FindObjectOfType <MapBoundaries>(); if (mb == null) { Debug.Log("no MapBoundaries found."); return; } //ArrowUtils.CheckTransportationModuleExist(); StationCreator creator = StationCreator.AttachToGameObject(); creator.SetStations(FindObjectsOfType <StationController>()); // SumoLocation used in UTM to WGS-84 conversion. var location = netInfo.location; // Go through the busStops in busInfo. foreach (var busStop in busInfo.busStops) { // Get the polyline of the lane of the busStop var lane = netInfo.GetLane(busStop.lane); // Get the midpoint of the first 2 positions of shape in lane. var midPoint = lane.GetMidPoint(); //Debug.Log(midPoint); // Get the UTM corrdinates by subtracting the netOffset in location-element. var utm = location.GetUTM(midPoint.x, midPoint.y); // Convert the UTM corrdinates to Latitude Longitude. var latlon = UTMtoLatLon(utm[0], utm[1], location.GetZone()); //Debug.Log(latlon[0] + ", " + latlon[1]); // Convert the Latitude Longitude to coordinates in Unity. var convVec = CoordinateConvertor.LatLonToVector3(latlon[0], latlon[1], 0, mb); //Debug.Log(convVec); // Create a busStop based on the converted coordinate. //var go = new GameObject(busStop.id); //go.transform.position = convVec; //go.transform.SetParent(this.transform); creator.AddNewStation(convVec, busStop.id); } 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"); }
void OnEnable() { creator = target as StationCreator; //creator.SetStations(GameObject.FindGameObjectsWithTag("TransStation")); creator.SetStations(FindObjectsOfType <StationController>()); }