我怎样才能在Unity上读取xml的xml?

时间:2017-04-13 12:01:17

标签: android xml unity3d

所以这里是我的代码,它在Unity编辑器中运行得很好,但在android上却没有,它只读取xml文件的第一行。 我不知道它有什么问题。 该文件存在于手机上但只读取第一行。 在统一编辑器中,它工作得很好。 谢谢你的帮助。

 using System.Xml;
 using System.Xml.Serialization;

 public class Mission
 { [XmlAttribute("id")]
 public int Id;

 public string description;
 public int ordre;

 }

这是加载xml

的类
using System.IO;
using System.Xml.Serialization;
using System.Collections.Generic;

[XmlRoot("Missionss")]
 public class Missions{
 [XmlArray("Missions"), XmlArrayItem("Mission")]
 public List<Mission> Mission_List;

 private Missions(){}

 public static Missions LoadFromFile(string filepath){
     XmlSerializer serializer = new XmlSerializer(typeof(Missions));
     using(FileStream stream = new FileStream(filepath, FileMode.Open))
     {
         return serializer.Deserialize(stream) as Missions;
     }
 } 
 public void Save (string path)
 {
     XmlSerializer serializer = new XmlSerializer (typeof(Missions));
     using (FileStream stream = new FileStream (path, FileMode.Create)) {
         serializer.Serialize (stream, this);
     }
    }
  }

最后:

public void LoadXML(){

     string filename="/phases.xml";
     string filename1="/missions.xml";

     phases = Phases.LoadFromFile(Application.persistentDataPath + filename);
     missions = Missions.LoadFromFile (Application.persistentDataPath + filename1);


 }

 public void save(){

     phases.Save(Application.streamingAssetsPath + "phases.xml");
     missions.Save(Application.streamingAssetsPath + "missions.xml");


 }

1 个答案:

答案 0 :(得分:0)

你不需要在某处写“\”吗?让我们说:phases.Save(Application.streamingAssetsPath +“\\”+ “phases.xml”);