コード例 #1
0
    /// <summary>
    /// Loads a scenario from the given XML-File. 
    /// Be sure that the file exists, is well formed and is in to corresponding directory.
    /// </summary>
    /// <returns></returns>
    public Scenario LoadScenario()
    {
        Scenario scenario = new Scenario();
        try
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(getCurrentInputFileName());
            XmlElement root = doc.DocumentElement;
            XmlNodeList list = root.GetElementsByTagName("TestCase");
            for (int i = 0; i < list.Count; i++)
            {
                TestCase t = new TestCase();
                t.id=Convert.ToInt32(list[i].Attributes["id"].Value);
                t.numElements = Convert.ToInt32(list[i].Attributes["numElements"].Value);
                t.targetElement = Convert.ToInt32(list[i].Attributes["targetElement"].Value);
                t.phoneIntensity[0]=Convert.ToInt32(list[i].Attributes["phoneIntensityMin"].Value);
                t.phoneIntensity[1]=Convert.ToInt32(list[i].Attributes["phoneIntensityMax"].Value);
                t.vibroIntensity[0]=Convert.ToInt32(list[i].Attributes["vibroIntensityMin"].Value);
                t.vibroIntensity[1]=Convert.ToInt32(list[i].Attributes["vibroIntensityMax"].Value);

                Vector3 scale = new Vector3();
                scale.x = (list[i].Attributes["scaleX"] != null) ? (float)Convert.ToDouble(list[i].Attributes["scaleX"].Value) : 40.0f;
                scale.y = (list[i].Attributes["scaleY"] != null) ? (float)Convert.ToDouble(list[i].Attributes["scaleY"].Value) : 10.0f;
                scale.z = (list[i].Attributes["scaleZ"] != null) ? (float)Convert.ToDouble(list[i].Attributes["scaleZ"].Value) : 20.0f;
                t.sceneScale = scale;
                scenario.AddTestCase(t);
            }
            if (list.Count == 0)
            {
                UIController.Instance.ReportError(getCurrentInputFileName() + ": No TestCases found!");
            }
        }
        catch (Exception ex)
        {
            Debug.Log("Xml Loading: " + ex.ToString());
            UIController.Instance.ReportError(getCurrentInputFileName() + " not found or is invalid! Please make sure that the corresponding file exists and is well formed!");
        }

        return scenario;
    }