-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLevelReader.cs
45 lines (36 loc) · 1.09 KB
/
LevelReader.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using UnityEngine;
using System.Collections;
using System.Xml;
using System.Collections.Generic;
public class LevelReader : MonoBehaviour {
XmlDocument levelDoc;
XmlNodeList levelist;
List<string> levelArray;
//private string level{get;set;}
// Use this for initialization
void Start () {
levelArray = new List<string> ();
levelDoc = new XmlDocument ();
TextAsset xmlfile = Resources.Load ("levels", typeof(TextAsset)) as TextAsset;
levelDoc.LoadXml (xmlfile.text);
levelist = levelDoc.GetElementsByTagName ("level");
foreach( XmlNode leveldata in levelist){
XmlNodeList levelinfo = leveldata.ChildNodes;
foreach(XmlNode data in levelinfo){
if(data.Name == "setup"){
levelArray.Add(data.InnerText);
// if(data.Name=="levelname")
// level=data.InnerText;
}
}
}
}
public void loadLevel(int nr){
string[] levString = levelArray[nr -1].Split(',');
//string sub = levString.Substring(0, levString.Length - 5);
foreach(string tile in levString)
{
GameObject.Find("MainCamera").GetComponent<LevelCreator>().SetTile(tile);
}
}
}