-
Notifications
You must be signed in to change notification settings - Fork 0
/
SaveChallengeButtons.cs
81 lines (70 loc) · 1.98 KB
/
SaveChallengeButtons.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
public class SaveChallengeButtons : MonoBehaviour {
public static SaveChallengeButtons instance;
[HideInInspector]
public bool[] bools = new bool[500];
[HideInInspector]
public bool[] star_Two = new bool[500];
[HideInInspector]
public bool[] star_Three = new bool[500];
// Use this for initialization
void Awake () {
if (instance == null){
instance = this;
DontDestroyOnLoad(gameObject);
}else if (instance !=this){
Destroy(gameObject);
}
Load();
}
public void SetCompleted(int i){
if (bools[i] == false){
bools[i] = true;
}
}
public void SetStarTwo(int i){
if (star_Two[i] == false){
star_Two[i] = true;
}
}
public void SetStarThree(int i){
if (star_Three[i] == false){
star_Three[i] = true;
}
}
public void Save () {
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Create(Application.persistentDataPath + "/challengeInfo.dat");
AvailableChallengeButtons data = new AvailableChallengeButtons();
data.bools = bools;
data.star_Two = star_Two;
data.star_Three = star_Three;
bf.Serialize(file,data);
file.Close();
}
public void Load(){
if (File.Exists(Application.persistentDataPath + "/challengeInfo.dat")){
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Open(Application.persistentDataPath + "/challengeInfo.dat",FileMode.Open);
AvailableChallengeButtons data = (AvailableChallengeButtons)bf.Deserialize(file);
file.Close();
bools = data.bools;
star_Two = data.star_Two;
star_Three = data.star_Three;
}
}
public void DeleteSaves(){
File.Delete(Application.persistentDataPath + "/challengeInfo.dat");
}
}
[Serializable]
class AvailableChallengeButtons{
public bool[] bools;
public bool[] star_Two;
public bool[] star_Three;
}