I need to load an exsisting xml file.
The xml located in StreamingAssets folder
There is my code
using UnityEngine;
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Xml;
public class LoadLevel : MonoBehaviour
{
public bool needLoad;
public bool playerIs;
public GameObject wallObj;
public GameObject cellObj;
public GameObject orbObj;
public GameObject player;
public GameObject gamePlay;
public int lvlNumber;
private string filename;
public Transform redCube;
public GUIText texter;
public GUIText texter2;
public WWW www;
void Start()
{
StartCoroutine("load");
}
void Update()
{
//texter.text = System.Convert.ToString(Path.DirectorySeparatorChar);
//texter.text = Path.GetFullPath(Application.dataPath);
}
public void LoadData ()
{
if(needLoad)
{
texter.text = "Load started";
//StartCoroutine("load");
//filename = "Levels/Level_"+ lvlNumber;
//MemoryStream assetStream = new MemoryStream(www.bytes);
//XmlTextReader reader = new XmlTextReader(assetStream);
XmlDocument xmlDoc = new XmlDocument ();
xmlDoc.Load(new StringReader(www.text));
//texter2.text = xmlDoc.InnerText;
XmlNodeList wallList = xmlDoc.GetElementsByTagName ("wall");
XmlNodeList orbList = xmlDoc.GetElementsByTagName ("orb");
XmlNodeList cellList = xmlDoc.GetElementsByTagName ("cell");
XmlNodeList playerSpawn = xmlDoc.GetElementsByTagName("playerSpawn");
foreach(XmlNode n in wallList)
{
string s1 = n.Attributes[0].Value;
float x_coord = System.Convert.ToSingle (s1);
s1 = n.Attributes[1].Value;
float y_coord = System.Convert.ToSingle (s1);
s1 = n.Attributes[2].Value;
float z_coord = System.Convert.ToSingle (s1);
GameObject.Instantiate(wallObj,new Vector3(x_coord,y_coord,z_coord),Quaternion.Euler(new Vector3(90,0,0)));
}
foreach(XmlNode n in orbList)
{
string s1 = n.Attributes[0].Value;
float x_coord = System.Convert.ToSingle (s1);
s1 = n.Attributes[1].Value;
float y_coord = System.Convert.ToSingle (s1);
s1 = n.Attributes[2].Value;
float z_coord = System.Convert.ToSingle (s1);
GameObject.Instantiate(orbObj,new Vector3(x_coord,y_coord,z_coord),Quaternion.Euler(new Vector3(90,0,0)));
}
foreach(XmlNode n in cellList)
{
string s1 = n.Attributes[0].Value;
float x_coord = System.Convert.ToSingle (s1);
s1 = n.Attributes[1].Value;
float y_coord = System.Convert.ToSingle (s1);
s1 = n.Attributes[2].Value;
float z_coord = System.Convert.ToSingle (s1);
s1 = n.Attributes[3].Value;
int isbig = System.Convert.ToInt32 (s1);
GameObject o = GameObject.Instantiate(cellObj,new Vector3(x_coord,y_coord,z_coord),Quaternion.Euler(new Vector3(90,0,0))) as GameObject ;
o.GetComponent<Cell>().bigDot = isbig;
}
foreach(XmlNode n in playerSpawn)
{
string s1 = n.Attributes[0].Value;
float x_coord = System.Convert.ToSingle (s1);
s1 = n.Attributes[1].Value;
float y_coord = System.Convert.ToSingle (s1);
s1 = n.Attributes[2].Value;
float z_coord = System.Convert.ToSingle (s1);
GameObject.Instantiate(player,new Vector3(x_coord,y_coord,z_coord),Quaternion.identity);
}
needLoad = false;
Messenger.Broadcast("Level Loaded");
StopCoroutine("load");
Debug.Log("Level Loaded");
}
}
IEnumerator load()
{
www = new WWW("jar:file://" + Application.dataPath + "!/assets/Level_" + lvlNumber + ".xml");
yield return www;
//texter.text = "Load complete";
texter2.text = www.text;
}
}
On phone screen i have a text from texter2.text = www.text;, but level not loading.
I think that the xml file not created from www.text;
Help pls, i can not solve this problem for the past three days…(