static void EditStation()
    {
        AddModuleIfNotExist(transModuleName);

        StationCreator creator = StationCreator.AttachToGameObject();

        Selection.activeGameObject = creator.gameObject;
    }
    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");
    }
Exemple #4
0
    public static StarSystem GetRandomStarSystem(int indexStarSystem)
    {
        Star star = StarCreator.CreateStar(indexStarSystem);

        return(new StarSystem
        {
            id = indexStarSystem,
            indexSystem = indexStarSystem,
            star = star,
            position = GetStarSistemPosition(indexStarSystem),
            planetSystemsArray = CreatePlanetSystems(star),
            oldX = oldX,
            oldY = oldY,

            StationArr = StationCreator.CreateTestStation(Settings.TEST.TEST_STATIONS_IN_SYSTEM)
        });
    }
    public override void OnInspectorGUI()
    {
        GUI.color = Color.gray;
        DrawDefaultInspector();
        creator = target as StationCreator;
        GUILayout.Space(10);

        if (editing)
        {
            if (creator.HasEditingStation)
            {
                GUI.color = Color.white;
                GUILayout.Label("Enter the name of the station");
                newStationName = GUILayout.TextField(newStationName);
                creator.SetEditStationName(newStationName);

                GUILayout.FlexibleSpace();
                GUI.color = Color.red;
                GUILayout.Label("Press this to remove the station");
                if (GUILayout.Button("Remove"))
                {
                    creator.RemoveStation();
                    editing = false;
                    adding  = false;
                }

                if (!adding)
                {
                    GUILayout.FlexibleSpace();
                    GUI.color = Color.white;
                    GUILayout.Label("Press this to undo changes");
                    if (GUILayout.Button("Undo"))
                    {
                        creator.RevertEditStation();
                        newStationName = creator.GetEditStationName();
                    }
                }

                GUILayout.FlexibleSpace();
                GUI.color = Color.yellow;
                if (GUILayout.Button("Save and go back"))
                {
                    creator.ReleaseEditStation();
                    editing = false;
                    adding  = false;
                }
            }
            else
            {
                GUI.color = Color.green;
                GUILayout.Label("Click on a station to edit,");
                GUILayout.Label("or click somewhere else to create a station...");

                GUILayout.FlexibleSpace();
                GUI.color = Color.yellow;
                if (GUILayout.Button("Back"))
                {
                    creator.ReleaseEditStation();
                    editing = false;
                    adding  = false;
                }
            }
        }
        else
        {
            GUI.color = Color.green;
            GUILayout.Label("Press this button to start");
            if (GUILayout.Button("Start editing"))
            {
                editing        = true;
                newStationName = creator.GetEditStationName();
            }

            GUILayout.FlexibleSpace();

            GUI.color = Color.white;
            GUILayout.Label("Press this button to exit 'Station Creator'");
            GUI.color = Color.yellow;
            if (GUILayout.Button("Exit"))
            {
                editing = false;
                DestroyImmediate(creator);
            }
        }
    }
 void OnEnable()
 {
     creator = target as StationCreator;
     //creator.SetStations(GameObject.FindGameObjectsWithTag("TransStation"));
     creator.SetStations(FindObjectsOfType <StationController>());
 }