Ejemplo n.º 1
0
    public Response[] LoadResponses(int idIn)
    {
        //Get statment id in
        //int idIn = 1;
        Response[] response_array = new Response[4];
        response_array[0] = new Response();
        response_array[1] = new Response();
        response_array[2] = new Response();
        response_array[3] = new Response();
        int index = -1;
        bool found = false;

        xml = (TextAsset)Resources.Load(response_xml);
        XmlDocument xmlDoc = new XmlDocument();

        xmlDoc.LoadXml(xml.text);
        //Debug.Log("REACHED");
        XmlNodeList choice_list = xmlDoc.GetElementsByTagName("choices");
        foreach(XmlNode dialog_fragment in choice_list){
            XmlNodeList xnl = dialog_fragment.ChildNodes;
            response = new Response();
            foreach(XmlNode xn in xnl ){

                if(xn.Name == "Response_ID" && xn.InnerText != idIn.ToString()){
                    found = false;
                }
                if(xn.Name == "Response_ID" && xn.InnerText == idIn.ToString()){
                    found = true;

                    index++;
                    //Debug.Log("Response_id : " + xn.InnerText);
                    response.SetResponseId(xn.InnerText);

                }
                if(xn.Name == "Text" && found){
                    //Debug.Log("TEXT: " + xn.InnerText);
                    response.SetText(xn.InnerText);
                }
                if(xn.Name == "AudioFile" && found){
                //	Debug.Log("Audio File: " + xn.InnerText);
                    response.SetAudioFile(xn.InnerText);
                }
                if(xn.Name == "Symbol" && found){
                //	Debug.Log("Symbol: " + xn.InnerText);
                    response.SetSymbol(xn.InnerText);
                }
                if(xn.Name == "NextStatement" && found){
                    //Debug.Log("Next Statement: " + xn.InnerText);
                    response.SetNextStatement(xn.InnerText);
                }

            }

                //Add to response array

            if(found)
            response_array[index] = response;

        }

          /*for(int i = 0; i < 4; i++){
            Debug.Log("Array test: " + response_array[i].getText());
        }*/

        //Return array
        return response_array;
    }