OK I know how to call and display xml file in unity from the asset list, but what do I need to change so that I can call from an xml that I just dump into the build folder so that I can edit it outside of unity without have to rebuild the project every time
Below is the ENTIRE project code it uses only one script at the moment
I want to call from an xml outside of unity
UPDATE–I have used the first answer to call the xml from outside the program by declaring the file path. But this is not enough as I need to call the file without knowing the exact location and if I could force the XML to build in the resource folder than part of the problem would be done
Is it possible to use a Application.datapath to call the XML without declaring an exact location?
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.IO;
public class TestGUI : MonoBehaviour {
public GUISkin testSkin;
public TextAsset QuestionList;
public Rect textAreaSize;
public Rect buttonSizeA;
public Rect buttonSizeB;
public Rect buttonSizeC;
public Rect buttonSizeD;
public Rect AnswerSizeA;
public Rect AnswerSizeB;
public Rect AnswerSizeC;
public Rect AnswerSizeD;
List<Dictionary<string,string>> levels = new List<Dictionary<string,string>>();
Dictionary<string,string> obj;
float width = 1024;
float height = 768;
static int actualLevel = 1;
static int LevelMaxNumber;
static int WaipointCounter = 0;
static string QuestionString = "";
static string AnswerStringA = "";
static string AnswerStringB = "";
static string AnswerStringC = "";
static string AnswerStringD = "";
string path = "C:/Users/MymIntern2/Desktop/Builds/testbuild_Data/gamexmldata.xml";
void OnGUI() {
GUI.skin = testSkin;
float resolutionX = Screen.width / width;
float resolutionY = Screen.height / height;
GUI.matrix = Matrix4x4.TRS(new Vector3(0, 0, 0), Quaternion.identity, new Vector3(resolutionX, resolutionY, 1));
GUI.TextArea (textAreaSize, QuestionString);
if(GUI.Button(buttonSizeA, "A")) // make a button
{
print ("Button A");
WaipointCounter = 4;
}
GUI.Label (AnswerSizeA, AnswerStringA);
if(GUI.Button(buttonSizeB, "B")) // make a button
{
print ("Button B");
}
GUI.Label (AnswerSizeB, AnswerStringB);
if(GUI.Button(buttonSizeC, "C")) // make a button
{
print ("Button C");
}
GUI.Label (AnswerSizeC, AnswerStringC);
if(GUI.Button(buttonSizeD, "D")) // make a button
{
print ("Button D");
}
GUI.Label (AnswerSizeD, AnswerStringD);
}
void Start()
{ //Timeline of the Level creator
GetLevel();
StartCoroutine(LevelStartInfo(1.0F));
LevelMaxNumber = levels.Count;
}
public void GetLevel()
{
XmlDocument xmlDoc = new XmlDocument(); // xmlDoc is the new xml document.
StreamReader reader = new StreamReader(path);
xmlDoc.LoadXml(reader.ReadToEnd()); // load the file.
reader.Close();
XmlNodeList levelsList = xmlDoc.GetElementsByTagName("level"); // array of the level nodes.
foreach (XmlNode levelInfo in levelsList)
{
XmlNodeList levelcontent = levelInfo.ChildNodes;
obj = new Dictionary<string,string>(); // Create a object(Dictionary) to colect the both nodes inside the level node and then put into levels[] array.
foreach (XmlNode levelsItens in levelcontent) // levels itens nodes.
{
//if(levelsItens.Name == "name")
//{
// obj.Add("name",levelsItens.InnerText); // put this in the dictionary.
//}
if(levelsItens.Name == "tutorial")
{
obj.Add("tutorial",levelsItens.InnerText); // put this in the dictionary.
}
if(levelsItens.Name == "object")
{
switch(levelsItens.Attributes["name"].Value)
{
case "Right": obj.Add("Right" ,levelsItens.InnerText); break; // put this in the dictionary.
case "Wrong1": obj.Add("Wrong1",levelsItens.InnerText); break; // put this in the dictionary.
case "Wrong2": obj.Add("Wrong2",levelsItens.InnerText); break; // put this in the dictionary.
case "Wrong3": obj.Add("Wrong3",levelsItens.InnerText); break; // put this in the dictionary.
}
}
//if(levelsItens.Name == "finaltext")
//{
// obj.Add("finaltext",levelsItens.InnerText); // put this in the dictionary.
//}
}
levels.Add(obj); // add whole obj dictionary in the levels[].
}
}
IEnumerator LevelStartInfo(float Wait)
{
//string lvlName = "";
//levels[actualLevel-1].TryGetValue("name",out lvlName);
string tutorial = "";
levels[actualLevel-1].TryGetValue("tutorial",out QuestionString);
levels[actualLevel-1].TryGetValue("Right" ,out AnswerStringA);
levels[actualLevel-1].TryGetValue("Wrong1",out AnswerStringB);
levels[actualLevel-1].TryGetValue("Wrong2",out AnswerStringC);
levels[actualLevel-1].TryGetValue("Wrong3",out AnswerStringD);
//levels[actualLevel-1].TryGetValue("finaltext",out finaltext);
yield return new WaitForSeconds(Wait);
}
void Update()
{
if(WaipointCounter == 4)
{
if(actualLevel<LevelMaxNumber)
{
actualLevel+=1;
WaipointCounter = 0;
StartCoroutine(FinishLevel(1.0F));
}
else
{
actualLevel=1;
WaipointCounter = 0;
StartCoroutine(FinishLevel(1.0F));
}
}
}
IEnumerator FinishLevel(float Wait)
{
//yield return new WaitForSeconds(Wait);
//GameObject FinalText_GUI = Instantiate(FinalText) as GameObject;
//FinalText_GUI.guiText.text = finaltext;
yield return new WaitForSeconds(3.0f);
Application.LoadLevel(0);
}
}