Skip to content

Commit f2e297d

Browse files
committed
fix(SaveLoad): Initialize save data flag
1 parent c7d6e52 commit f2e297d

File tree

4 files changed

+29
-8
lines changed

4 files changed

+29
-8
lines changed

Assets/JCSUnity/Scripts/SaveLoad/JCS_AppData.cs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99
using System;
1010
using UnityEngine;
11+
using MyBox;
1112

1213
namespace JCSUnity
1314
{
@@ -19,15 +20,28 @@ public abstract class JCS_AppData
1920
{
2021
/* Variables */
2122

22-
private bool mInitialized = false;
23+
[Separator("Runtime Variables (JCS_AppData)")]
2324

25+
[Tooltip("The copyright information.")]
2426
public string Copyright = "";
27+
28+
[Tooltip("The resource version.")]
2529
public string Version = "";
26-
30+
31+
[Tooltip("Set to true when the data is initialized.")]
32+
[SerializeField]
33+
[ReadOnly]
34+
private bool mInitialized = false;
35+
2736
/* Setter & Getter */
2837

2938
/* Functions */
3039

40+
protected JCS_AppData()
41+
{
42+
InitFile();
43+
}
44+
3145
protected void InitFile()
3246
{
3347
var pds = JCS_PackageDataSettings.instance;
@@ -41,15 +55,16 @@ protected void InitFile()
4155
Copyright = pds.CopyrightString;
4256
Version = pds.VersionString;
4357

44-
this.mInitialized = true;
58+
// Set init flag.
59+
mInitialized = true;
4560
}
4661

4762
/// <summary>
4863
/// Return true if data is initialized.
4964
/// </summary>
50-
public bool Initialized()
51-
{
52-
return this.mInitialized;
65+
public bool Initialized()
66+
{
67+
return this.mInitialized;
5368
}
5469

5570
/// <summary>

Assets/JCSUnity/Scripts/SaveLoad/JCS_BinData.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* $Notice: See LICENSE.txt for modification and distribution information
77
* Copyright © 2018 by Shen, Jen-Chieh $
88
*/
9+
using System;
910
using System.IO;
1011
using System.Runtime.Serialization.Formatters.Binary;
1112

@@ -14,7 +15,7 @@ namespace JCSUnity
1415
/// <summary>
1516
/// Interface of storing game data as binary format.
1617
/// </summary>
17-
[System.Serializable]
18+
[Serializable]
1819
public abstract class JCS_BinData : JCS_AppData
1920
{
2021
/* Variables */

Assets/JCSUnity/Scripts/SaveLoad/JCS_JSONData.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* $Notice: See LICENSE.txt for modification and distribution information
77
* Copyright © 2019 by Shen, Jen-Chieh $
88
*/
9+
using System;
910
using System.IO;
1011
using System.Text;
1112
using Newtonsoft.Json;
@@ -15,7 +16,7 @@ namespace JCSUnity
1516
/// <summary>
1617
/// Interface to store game data in JSON format.
1718
/// </summary>
18-
[System.Serializable]
19+
[Serializable]
1920
public abstract class JCS_JSONData : JCS_AppData
2021
{
2122
/* Variables */
@@ -93,10 +94,12 @@ public static T LoadFromFile<T>(string fullFilePath)
9394
using (var stream = new FileStream(fullFilePath, FileMode.Open))
9495
{
9596
string contents = "";
97+
9698
using (var sr = new StreamReader(stream))
9799
{
98100
contents = sr.ReadToEnd();
99101
}
102+
100103
return JsonConvert.DeserializeObject<T>(contents);
101104
}
102105
}

Assets/JCSUnity/Scripts/SaveLoad/JCS_XMLData.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* $Notice: See LICENSE.txt for modification and distribution information
77
* Copyright (c) 2016 by Shen, Jen-Chieh $
88
*/
9+
using System;
910
using System.IO;
1011
using System.Xml.Serialization;
1112

@@ -14,6 +15,7 @@ namespace JCSUnity
1415
/// <summary>
1516
/// Interface of storing game data as XML format.
1617
/// </summary>
18+
[Serializable]
1719
public abstract class JCS_XMLData : JCS_AppData
1820
{
1921
/* Variables */

0 commit comments

Comments
 (0)