-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLevels.cs
More file actions
66 lines (63 loc) · 1.58 KB
/
Levels.cs
File metadata and controls
66 lines (63 loc) · 1.58 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class Level
{
public List<string> m_Rows = new List<string>();
public int Height
{
get
{
return m_Rows.Count;
}
}
public int Width
{
get
{
int maxLenght = 0;
foreach (var r in m_Rows)
{
if (r.Length > maxLenght)
{
maxLenght = r.Length;
}
}
return maxLenght;
}
}
}
public class Levels : MonoBehaviour
{
public string filename;
public List<Level> m_Levels;
private void Awake()
{
TextAsset textAsset = (TextAsset)Resources.Load(filename);
if (!textAsset)
{
Debug.Log("Levels_ " + filename + ".txt does not exist!");
return;
}
else
{
Debug.Log("Levels imported");
}
string completeText = textAsset.text;
string[] lines;
lines = completeText.Split(new string[] { "\n" }, System.StringSplitOptions.None);
m_Levels.Add(new Level());
for (long i = 0; i < lines.LongLength; i++)
{
string line = lines[i];
if (line.StartsWith(";"))
{
Debug.Log("New level added");
m_Levels.Add(new Level());
continue;
}
m_Levels[m_Levels.Count - 1].m_Rows.Add(line);
}
}
}