|
2 | 2 | using System; |
3 | 3 | using System.IO; |
4 | 4 |
|
5 | | -[System.Serializable] |
6 | | -public class SaveFile : ISaveFile |
| 5 | +namespace UnityBinaryFileSaver |
7 | 6 | { |
8 | | - string filename; |
9 | | - Action<string> callback; |
10 | | - ISaveContainer data; |
11 | | - [System.NonSerialized] |
12 | | - FileStream filestream; |
13 | | - |
14 | | - public SaveFile(string filename) |
| 7 | + [System.Serializable] |
| 8 | + public class SaveFile : ISaveFile |
15 | 9 | { |
16 | | - this.filename = Application.persistentDataPath + "/" + filename; |
17 | | - } |
| 10 | + string filename; |
| 11 | + Action<string> callback; |
| 12 | + ISaveContainer data; |
| 13 | + [System.NonSerialized] |
| 14 | + FileStream filestream; |
18 | 15 |
|
19 | | - public SaveFile(string filename, ISaveContainer data) |
20 | | - { |
21 | | - this.filename = Application.persistentDataPath + "/" + filename; |
22 | | - this.data = data; |
23 | | - } |
| 16 | + string Path |
| 17 | + { |
| 18 | + get { |
| 19 | + return Application.persistentDataPath + "/"; |
| 20 | + } |
| 21 | + } |
24 | 22 |
|
25 | | - public ISaveContainer Data |
26 | | - { |
27 | | - get { return data; } |
28 | | - set { data = value; } |
29 | | - } |
| 23 | + string Filename |
| 24 | + { |
| 25 | + get { |
| 26 | + return Path + filename; |
| 27 | + } |
| 28 | + } |
30 | 29 |
|
31 | | - public FileStream Writefile |
32 | | - { |
33 | | - get |
| 30 | + public SaveFile(string filename) |
34 | 31 | { |
35 | | - filestream = File.Create(filename); |
36 | | - return filestream; |
| 32 | + this.filename = filename; |
37 | 33 | } |
38 | | - } |
39 | 34 |
|
40 | | - public FileStream Readfile |
41 | | - { |
42 | | - get |
| 35 | + public SaveFile(string filename, ISaveContainer data) |
43 | 36 | { |
44 | | - if (!File.Exists(filename)) return null; |
45 | | - filestream = File.Open(filename, FileMode.Open); |
46 | | - return filestream; |
| 37 | + this.filename = filename; |
| 38 | + this.data = data; |
47 | 39 | } |
48 | | - } |
49 | 40 |
|
50 | | - public void Close() |
51 | | - { |
52 | | - filestream.Close(); |
| 41 | + public ISaveContainer Data |
| 42 | + { |
| 43 | + get { return data; } |
| 44 | + set { data = value; } |
| 45 | + } |
| 46 | + |
| 47 | + public FileStream Writefile |
| 48 | + { |
| 49 | + get |
| 50 | + { |
| 51 | + filestream = File.Create(Filename); |
| 52 | + return filestream; |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + public FileStream Readfile |
| 57 | + { |
| 58 | + get |
| 59 | + { |
| 60 | + if (!File.Exists(Filename)) return null; |
| 61 | + filestream = File.Open(Filename, FileMode.Open); |
| 62 | + return filestream; |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + public void Close() |
| 67 | + { |
| 68 | + filestream.Close(); |
| 69 | + } |
53 | 70 | } |
54 | 71 | } |
0 commit comments