Example #1
0
    public static void LoadSumoCFG(string path)
    {
        string dirPath = Path.GetDirectoryName(path);
        //Debug.Log(dirPath);

        var doc = new XmlDocument();

        doc.Load(path);
        var node    = doc.GetElementsByTagName("net-file")[0];
        var netPath = node.Attributes["value"].Value;

        node = doc.GetElementsByTagName("route-files")[0];
        var routePath = node.Attributes["value"].Value;

        node = doc.GetElementsByTagName("additional-files")[0];
        var additionalPath = node.Attributes["value"].Value;

        netPath        = Path.Combine(dirPath, netPath);
        routePath      = Path.Combine(dirPath, routePath);
        additionalPath = Path.Combine(dirPath, additionalPath);

        //Debug.Log(netPath);
        //Debug.Log(routePath);
        //Debug.Log(additionalPath);

        //string lane;
        AdditionalContainer addContainer;

        using (var stream = new FileStream(additionalPath, FileMode.Open))
        {
            var serializer = new XmlSerializer(typeof(AdditionalContainer));
            addContainer = serializer.Deserialize(stream) as AdditionalContainer;
            //lane = addContainer.busStops[0].lane;
            //Debug.Log(lane);
            //foreach (var item in container.busStops)
            //{
            //    Debug.Log(item.id + ", " + item.lane);
            //}
        }
        NetContainer netContainer;

        using (var stream = new FileStream(netPath, FileMode.Open))
        {
            var serializer = new XmlSerializer(typeof(NetContainer));
            netContainer = serializer.Deserialize(stream) as NetContainer;
            //Debug.Log(container.GetLane(lane));
            //Debug.Log(container.location.origBoundary);
        }

        var go = SumoContainer.CreateGameObject(addContainer, netContainer);

        go.transform.SetParent(GameObject.Find("Transportation").transform);

        var sumoContainer = go.GetComponent <SumoContainer>();

        sumoContainer.CreateBusStops();
        sumoContainer.CreateBusLines();
    }
    static void LoadSumoData()
    {
        AddModuleIfNotExist(transModuleName);
        var path = EditorUtility.OpenFilePanel("Load Sumo Data", "Assets/Transportations", "");

        if (path.Length == 0)
        {
            EditorUtility.DisplayDialog("Loading Cancelled", "No file was provided", "OK");
            return;
        }
        //Remove ModuleAll();
        SumoContainer.LoadSumoCFG(path);
    }