示例#1
0
 /// <summary>
 /// Exit BotNavSim.state behaviour: remove environment, clear paths
 /// </summary>
 public static void Exit()
 {
     CamController.ClearAreaList();
     CamController.ClearViewModeList();
     environment.transform.Recycle();
     paths.Clear();
 }
示例#2
0
 /// <summary>
 /// Exit simulation.
 /// </summary>
 public static void Exit()
 {
     Debug.Log("Simulation Exit.");
     Instance.StopAllCoroutines();
     settings = null;
     if (Log.logging)
     {
         Log.Stop(StopCode.Unspecified);
     }
     if (robot)
     {
         robot.Recycle();
     }
     if (environment)
     {
         environment.transform.Recycle();
     }
     CamController.ClearAreaList();
     CamController.ClearViewModeList();
     state = State.inactive;
 }
示例#3
0
    /// <summary>
    /// Main routine for loading a CSV log file.
    /// </summary>
    /// <param name="csvFilePath">Csv file path.</param>
    static IEnumerator LoadCsvRoutine(string csvFilePath)
    {
        loading = true;

        string csvPath     = Path.GetDirectoryName(csvFilePath);
        string csvFileName = Path.GetFileName(csvFilePath);

        // try opening the file with StreamReader
        StreamReader sr;

        try {
            sr = new StreamReader(csvFilePath);
        }
        catch (Exception e) {
            // log exception
            Debug.LogException(e);
            UI_Toolbar.I.additionalWindows.Add(
                new UI_Prompt(
                    PromptResponse,
                    UI_Prompt.Type.Close,
                    "File Load Exception!",
                    "See log for details"
                    )
                );
            // stop loading
            loading = false;
            yield break;
        }

        // inspect CSV header
        string line;
        string header      = "";
        string xmlFileName = null;

        while ((line = sr.ReadLine()) != null)
        {
            // stop inspecting when comments are no longer found
            if (!line.StartsWith(Strings.csvComment))
            {
                break;
            }
            header += line;
            // find XML filename stored in CSV
            if (line.Contains(Strings.csvXmlCommentTag))
            {
                xmlFileName = line.Substring(
                    line.IndexOf(Strings.csvXmlCommentTag) +
                    Strings.csvXmlCommentTag.Length);
                Debug.Log("XML filename from CSV is: " + xmlFileName);
            }
        }

        // temporary settings object for deserialization
        Simulation.Settings settings;


        // if xml filename was not found in csv...
        if (xmlFileName == null)
        {
            settings = new Simulation.Settings();
            // prompt user whether to select environment
            _waitingForResponse = true;
            UI_Toolbar.I.additionalWindows.Add(
                new UI_Prompt(
                    PromptResponse,
                    UI_Prompt.Type.YesNo,
                    "XML filename not found in CSV header!",
                    header + "\n Select environment to load?"
                    )
                );
            while (_waitingForResponse)
            {
                yield return(new WaitForSeconds(0.1f));
            }
            if (_response)
            {
                /// not yet implemented
                // browse environments and load selection
                Debug.Log("Not yet implemented: browse and load environment");
            }
        }
        else
        {
            // try loading environment
            settings = ObjectSerializer.DeSerializeObject <Simulation.Settings>(csvPath + "\\" + xmlFileName);
            // if environment is different to the currently loaded environment
            // prompt user for action  (discard other paths, or load new env and paths?)
            // (not yet implemented)
            if (environment)
            {
                if (environment.name != settings.environmentName)
                {
                    _waitingForResponse = true;
                    UI_Toolbar.I.additionalWindows.Add(
                        new UI_Prompt(
                            PromptResponse,
                            UI_Prompt.Type.OkCancel,
                            "Load new environment and paths?",
                            "CSV log is for a different environment. Load new environment and paths instead?"
                            )
                        );
                    while (_waitingForResponse)
                    {
                        yield return(new WaitForSeconds(0.1f));
                    }
                    if (_response)
                    {
                        // load environment and clear paths if YES
                        paths.Clear();
                        CamController.ClearAreaList();
                        LoadEnvironment(settings.environmentName);
                    }
                    else
                    {
                        // stop loading if NO
                        loading = false;
                        yield break;
                    }
                }
            }
            else
            {
                LoadEnvironment(settings.environmentName);
            }
        }

        // load paths from CSV and display them

        // go to line with SimulationTime as first string
        while ((line = sr.ReadLine()) != null)
        {
            if (line.StartsWith(Log.Parameters.SimulationTime.ToString()))
            {
                break;
            }
        }

        // extract headings and store column indexes for path types
        int robotPositionIndex;

        string[] row = line.Split(Strings.csvDelimiter);
        for (robotPositionIndex = 0; robotPositionIndex < row.Length; robotPositionIndex++)
        {
            if (row[robotPositionIndex] == Log.Parameters.RobotPosition.ToString())
            {
                break;
            }
        }


        BotPath botpos = new BotPath();

        botpos.csvName = csvFileName;

        // Build BotPath objects for each path type columns found
        while ((line = sr.ReadLine()) != null)
        {
            row = line.Split(Strings.csvDelimiter);
            if (robotPositionIndex > row.Length)
            {
                Debug.LogWarning("LogLoader: row length too short?");
                continue;
            }
            // try deserializing this vector3 data
            // (catch parsing errors not yet implemented)
            Vector3 pos = ParseVector3(row[robotPositionIndex]);
            // remove " chars from "12.3", for example
            // (catch parsing errors not yet implemented)
            float time = float.Parse(row[0].Substring(1, row[0].Length - 2));
            botpos.AddNode(pos, time);
        }


        AddPath(botpos);
        UpdatePathColors();
        loading = false;
    }