static void getRandomTextTree(XmlNode node, CharacterTalkText obj)
 {
     XmlNodeList list = node.ChildNodes;
     foreach (XmlNode c in list) {
         obj.addRandomText(c.FirstChild.Value);
     }
 }
Example #2
0
 public static PlayTalkText createSequenceTextFromCharacterTalkText(CharacterTalkText talktext,MessageMenu displaymenu)
 {
     StringBuilder stb = new StringBuilder();
     foreach(KeyValuePair<int,string> pair in talktext.SequenceTexts)
     {
         stb.Append(pair.Value);
     }
     return new PlayTalkText(stb.ToString(),displaymenu);
 }
    static void getSequenceTextTree(XmlNode node, CharacterTalkText obj)
    {
        XmlNodeList list = node.ChildNodes;
        foreach (XmlNode c in list)
        {
            int key = 0;
            string value = "";
            foreach (XmlNode d in c.ChildNodes) {

                if (d.LocalName.Equals("Key"))
                {
                    //Debug.Log("Key: "+ d.FirstChild.Value);
                    key = int.Parse(d.FirstChild.Value);
                }
                else if (d.LocalName.Equals("Value")) {
                    //Debug.Log("Value: " + d.FirstChild.Value);
                    value = d.FirstChild.Value;
                }
            }
            //Debug.Log(key+","+value);
            obj.addSequenceText(value, key);
        }
    }
    public static CharacterTalkText loadXML(string charactername)
    {
        string filename = getFilePath(charactername);
        CharacterTalkText obj = new CharacterTalkText();
        //保存先のファイル名

        //DataContractSerializerオブジェクトを作成
        DataContractSerializer serializer =
            new DataContractSerializer(typeof(CharacterTalkText));
        //読み込むファイルを開く
        XmlReader xr = XmlReader.Create(filename);

        XmlDocument doc = new XmlDocument();
        doc.Load(filename);
        XmlNode root = doc.LastChild;
        //Debug.Log(root.Name+", "+root.Value);
        XmlNodeList list = doc.GetElementsByTagName(CharacterTalkText.xmlnameRandom);
        //showNodes(list);
        getRandomTextTree(list[0],obj);
        list = doc.GetElementsByTagName(CharacterTalkText.xmlnameSequence);
        getSequenceTextTree(list[0],obj);
        list = doc.GetElementsByTagName(CharacterTalkText.xmlnameRestartKey);
        //Debug.Log(list[0].Name +", "+list[0].FirstChild.Value);
        obj.KeyOfRestart = int.Parse(list[0].FirstChild.Value);
        list = doc.GetElementsByTagName(CharacterTalkText.xmlnameTextLoop);
        obj.TextLoop = bool.Parse(list[0].FirstChild.Value);
        Debug.Log("END!");
        //Debug.Log(obj.RandomTexts.Count);
        //Debug.Log(obj.SequenceTexts.Count);
        //XMLファイルから読み込み、逆シリアル化する
        //CharacterTalkText obj = (CharacterTalkText)serializer.ReadObject(xr);
        //ファイルを閉じる
        xr.Close();
        //return obj;

        return obj;
    }