-
Notifications
You must be signed in to change notification settings - Fork 0
/
SaveManager.cs
98 lines (82 loc) · 2.06 KB
/
SaveManager.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
public class SaveManager : MonoBehaviour {
public static SaveManager instance;
[HideInInspector] public int f1; //HighScore
[HideInInspector] public int f2; //Coins
[HideInInspector] public int f3; //Ball ID
[HideInInspector] public int f4; //Background ID
[HideInInspector] public bool f5; //He Knows.. "Hides the tutor from start"
// Use this for initialization
void Awake () {
if (instance == null){
instance = this;
DontDestroyOnLoad(gameObject);
}else if (instance !=this){
Destroy(gameObject);
}
Load();
}
public int SetHighScore(int newf1){
if (newf1 >= f1){
f1 = newf1;
}
return f1;
}
public int SetCoins(int newCoins){
f2 += newCoins;
return f2;
}
public int SetBallID(int newf3){
f3 = newf3;
return f3;
}
public int SetBackgroundID(int newf4){
f4 = newf4;
return f4;
}
public void HeKnowsBool(){
f5 = true;
}
public void Save () {
Debug.Log("Save");
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Create(Application.persistentDataPath + "/playerInfo.dat");
PlayerData data = new PlayerData();
data.f1 = f1;
data.f2 = f2;
data.f3 = f3;
data.f4 = f4;
data.f5 = f5;
bf.Serialize(file,data);
file.Close();
}
public void Load(){
if (File.Exists(Application.persistentDataPath + "/playerInfo.dat")){
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Open(Application.persistentDataPath + "/playerInfo.dat",FileMode.Open);
PlayerData data = (PlayerData)bf.Deserialize(file);
file.Close();
f1 = data.f1;
f2 = data.f2;
f3 = data.f3;
f4 = data.f4;
f5 = data.f5;
}
}
public void DeleteSaves(){
File.Delete(Application.persistentDataPath + "/playerInfo.dat");
}
}
[Serializable]
class PlayerData{
public int f1;
public int f2;
public int f3;
public int f4;
public bool f5;
}