Пример #1
0
    public NPC[] LoadNpcs(int levelIn)
    {
        //Get level in
        //int levelIn = 1;
        NPC npc;
        NPC[] npc_array = new NPC[2];
        int index = -1;
        bool found = false;

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

        xmlDoc.LoadXml(xml.text);
        //Debug.Log("REACHED");
        XmlNodeList npc_list = xmlDoc.GetElementsByTagName("Character");
        foreach(XmlNode dialog_fragment in npc_list){
            XmlNodeList xnl = dialog_fragment.ChildNodes;
            npc = new NPC();
            foreach(XmlNode xn in xnl ){

                //ADD NPC ID TO DATABASE

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

                    index++;
                    //Debug.Log("Response_id : " + xn.InnerText);
                    npc.SetLevel(xn.InnerText);

                }
                    if(xn.Name == "Name" && found){
                //	Debug.Log("Symbol: " + xn.InnerText);
                    npc.SetName(xn.InnerText);
                }
                if(xn.Name == "Portrait" && found){
                    //Debug.Log("TEXT: " + xn.InnerText);
                    npc.SetPortrait(xn.InnerText);
                }
                if(xn.Name == "Image" && found){
                //	Debug.Log("Audio File: " + xn.InnerText);
                    npc.SetImage(xn.InnerText);
                }

                if(xn.Name == "Statement_ID" && found){
                    //Debug.Log("Next Statement: " + xn.InnerText);
                    npc.SetStatementId(xn.InnerText);
                }

                if(xn.Name == "Position" && found){
                    //Debug.Log("Next Statement: " + xn.InnerText);
                    npc.SetPosition(xn.InnerText);
                }

            }

                //Add to response array

            if(found)
            npc.SetStatements(npc.GetName());
            npc_array[index] = npc;

        }

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

        //Return array
        return npc_array;
    }