Question by
Bakhishov · Sep 30, 2016 at 07:54 PM ·
androidxmlxmlserializer
Please help me save and load XML file from Resources(
private void Awake() { path = Application.persistentDataPath + "/SavedGame.xml"; }
public void Save(){
XElement root = new XElement ("Root");
foreach (SaveableObject obj in objects) {
root.Add(obj.GetElement());
}
root.AddFirst(new XElement("score", Data.score));
XDocument saveDoc = new XDocument (root);
File.WriteAllText (path, saveDoc.ToString ());
}
public void Load(){
XElement root = null;
if (!File.Exists (path)) {
if (File.Exists (Application.persistentDataPath + "/NewGame.xml")) {
root = XDocument.Parse (File.ReadAllText (Application.persistentDataPath + "/NewGame.xml")).Element ("Root");
}
} else {
root = XDocument.Parse (File.ReadAllText (path)).Element ("Root");
}
if (root == null) {
return;
}
GenerateScene (root);
}
public void CreateNewGame(){
XElement root = null;
if (File.Exists (Application.persistentDataPath + "/NewGame.xml")) {
root = XDocument.Parse (File.ReadAllText (Application.persistentDataPath + "/NewGame.xml")).Element ("Root");
} else {
return;
}
if (root == null) {
return;
}
GenerateScene (root);
}
Comment
Answer by nonathaj · Oct 01, 2016 at 03:10 AM
You're going to want to look into TextAssets (Manual, Script Ref). They are for loading text files for parsing from Resources or the AssetDatabase.
Answer by Bakhishov · Oct 01, 2016 at 05:23 AM
I am beginer.I think fix on this script.But i dont know how to fix it.Sorry for bad English)