Line | |
---|
1 | using System;
|
---|
2 | using System.IO;
|
---|
3 | using System.Runtime.Serialization;
|
---|
4 | using System.Runtime.Serialization.Formatters.Binary;
|
---|
5 |
|
---|
6 | namespace AllocsFixes.PersistentData
|
---|
7 | {
|
---|
8 | [Serializable]
|
---|
9 | public class PersistentContainer
|
---|
10 | {
|
---|
11 | private Players players;
|
---|
12 |
|
---|
13 | public Players Players {
|
---|
14 | get {
|
---|
15 | if (players == null)
|
---|
16 | players = new Players ();
|
---|
17 | return players;
|
---|
18 | }
|
---|
19 | }
|
---|
20 |
|
---|
21 | private static PersistentContainer instance;
|
---|
22 |
|
---|
23 | public static PersistentContainer Instance {
|
---|
24 | get {
|
---|
25 | if (instance == null) {
|
---|
26 | instance = new PersistentContainer ();
|
---|
27 | }
|
---|
28 | return instance;
|
---|
29 | }
|
---|
30 | }
|
---|
31 |
|
---|
32 | private PersistentContainer ()
|
---|
33 | {
|
---|
34 | }
|
---|
35 |
|
---|
36 | public void Save ()
|
---|
37 | {
|
---|
38 | Stream stream = File.Open (StaticDirectories.GetSaveGameDir () + "/AllocsPeristentData.bin", FileMode.Create);
|
---|
39 | BinaryFormatter bFormatter = new BinaryFormatter ();
|
---|
40 | bFormatter.Serialize (stream, this);
|
---|
41 | stream.Close ();
|
---|
42 | }
|
---|
43 |
|
---|
44 | public static bool Load ()
|
---|
45 | {
|
---|
46 | if (File.Exists (StaticDirectories.GetSaveGameDir () + "/AllocsPeristentData.bin")) {
|
---|
47 | PersistentContainer obj;
|
---|
48 | Stream stream = File.Open (StaticDirectories.GetSaveGameDir () + "/AllocsPeristentData.bin", FileMode.Open);
|
---|
49 | BinaryFormatter bFormatter = new BinaryFormatter ();
|
---|
50 | obj = (PersistentContainer)bFormatter.Deserialize (stream);
|
---|
51 | stream.Close ();
|
---|
52 | instance = obj;
|
---|
53 | return true;
|
---|
54 | } else
|
---|
55 | return false;
|
---|
56 | }
|
---|
57 |
|
---|
58 | }
|
---|
59 | }
|
---|
60 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.