-
Notifications
You must be signed in to change notification settings - Fork 1
/
SaveTemplate.cs
68 lines (65 loc) · 1.62 KB
/
SaveTemplate.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
public abstract class SaveTemplate
{
/// <summary>
/// Marks the seperation of data in a string
/// </summary>
protected const char DataSplitter = ';';
/// <summary>
/// File Path for Saved Data
/// </summary>
protected abstract string filePath { get; }
/// <summary>
/// Save Data to File
/// </summary>
public void Save() => FileManager.WriteToFile(GetData(), filePath);
/// <summary>
/// Load Data from File
/// </summary>
public void Load() => InterpretData(GetData());
/// <summary>
///
/// </summary>
protected abstract string[] GetData();
/// <summary>
/// Interprets the Data from the File, assigning all of the values
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
protected abstract void InterpretData(string[] data);
protected int ParseToInt(string value)
{
try
{
return int.Parse(value);
}
catch (System.Exception)
{
//Debug.LogError("Data was unable to be parsed");
return 0;
}
}
protected float ParseToFloat(string value)
{
try
{
return float.Parse(value);
}
catch (System.Exception)
{
//Debug.LogError("Data was unable to be parsed");
return 0;
}
}
protected double ParseToDouble(string value)
{
try
{
return double.Parse(value);
}
catch (System.Exception)
{
//Debug.LogError("Data was unable to be parsed");
return 0;
}
}
}