-
Notifications
You must be signed in to change notification settings - Fork 0
/
SaveButtonsState.cs
60 lines (50 loc) · 1.42 KB
/
SaveButtonsState.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
public class SaveButtonsState : MonoBehaviour {
public static SaveButtonsState instance;
[HideInInspector]
public bool[] bools = 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 SetPurchase(int i){
if (bools[i] == false){
bools[i] = true;
}
}
public void Save () {
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Create(Application.persistentDataPath + "/buttonInfo.dat");
BallButtonsState data = new BallButtonsState();
data.bools = bools;
bf.Serialize(file,data);
file.Close();
}
public void Load(){
if (File.Exists(Application.persistentDataPath + "/buttonInfo.dat")){
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Open(Application.persistentDataPath + "/buttonInfo.dat",FileMode.Open);
BallButtonsState data = (BallButtonsState)bf.Deserialize(file);
file.Close();
bools =data.bools;
}
}
public void DeleteSaves(){
File.Delete(Application.persistentDataPath + "/buttonInfo.dat");
}
}
[Serializable]
class BallButtonsState{
public bool[] bools;
}