-
Notifications
You must be signed in to change notification settings - Fork 0
/
Data.cs
110 lines (107 loc) · 3.96 KB
/
Data.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// use File
using System.IO;
public static class Data
{
public static Dictionary<string, int> unlockedSkills = new Dictionary<string, int>();
public static int gold;
public static bool beatenTutorial;
public static bool beatenLevel1;
public static bool beatenLevel2;
public static bool beatenLevel3;
public static bool beatenLevel4;
public static void saveData()
{
string data = "";
data += "unlockedSkills:";
foreach (KeyValuePair<string, int> entry in unlockedSkills)
{
data += entry.Key + "," + entry.Value + "|";
}
// foreach (string skill in unlockedSkills)
// {
// data += skill + ",";
// }
data += ";";
data += "gold:" + gold + ";";
data += "beatenTutorial:" + beatenTutorial + ";";
data += "beatenLevel1:" + beatenLevel1 + ";";
data += "beatenLevel2:" + beatenLevel2 + ";";
data += "beatenLevel3:" + beatenLevel3 + ";";
data += "beatenLevel4:" + beatenLevel4 + ";";
File.WriteAllText(Application.persistentDataPath + "/data.txt", data);
}
public static void loadData()
{
if (File.Exists(Application.persistentDataPath + "/data.txt"))
{
string data = File.ReadAllText(Application.persistentDataPath + "/data.txt");
string[] dataSplit = data.Split(';');
foreach (string dataPiece in dataSplit)
{
string[] dataPieceSplit = dataPiece.Split(':');
if (dataPieceSplit[0] == "unlockedSkills")
{
unlockedSkills = new Dictionary<string, int>();
string[] skills = dataPieceSplit[1].Split('|');
foreach (string skill in skills)
{
if (skill != "")
{
string[] skillSplit = skill.Split(',');
unlockedSkills.Add(skillSplit[0], int.Parse(skillSplit[1]));
}
}
// string[] skills = dataPieceSplit[1].Split(',');
// foreach (string skill in skills)
// {
// if (skill != "")
// {
// unlockedSkills.Add(skill);
// }
// }
}
else if (dataPieceSplit[0] == "gold")
{
gold = int.Parse(dataPieceSplit[1]);
}
else if (dataPieceSplit[0] == "beatenTutorial")
{
beatenTutorial = bool.Parse(dataPieceSplit[1]);
}
else if (dataPieceSplit[0] == "beatenLevel1")
{
beatenLevel1 = bool.Parse(dataPieceSplit[1]);
}
else if (dataPieceSplit[0] == "beatenLevel2")
{
beatenLevel2 = bool.Parse(dataPieceSplit[1]);
}
else if (dataPieceSplit[0] == "beatenLevel3")
{
beatenLevel3 = bool.Parse(dataPieceSplit[1]);
}
else if (dataPieceSplit[0] == "beatenLevel4")
{
beatenLevel4 = bool.Parse(dataPieceSplit[1]);
}
}
}
}
public static void DebugLogData()
{
Debug.Log("unlockedSkills:");
foreach (KeyValuePair<string, int> entry in unlockedSkills)
{
Debug.Log(entry.Key + "," + entry.Value);
}
Debug.Log("gold:" + gold);
Debug.Log("beatenTutorial:" + beatenTutorial);
Debug.Log("beatenLevel1:" + beatenLevel1);
Debug.Log("beatenLevel2:" + beatenLevel2);
Debug.Log("beatenLevel3:" + beatenLevel3);
Debug.Log("beatenLevel4:" + beatenLevel4);
}
}