Skip to content

Commit

Permalink
feat: Replace built-int JSON serializer with newtonsoft
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs090218 committed Jan 18, 2025
1 parent 1410605 commit f372c90
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 54 deletions.
28 changes: 14 additions & 14 deletions Assets/JCSUnity/Scripts/SaveLoad/JCS_JSONData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
using System.IO;
using System.Text;
using UnityEngine;
using Newtonsoft.Json;

namespace JCSUnity
{
Expand All @@ -25,11 +25,11 @@ public abstract class JCS_JSONData : JCS_AppData
/* Functions */

/// <summary>
/// Save the game data into xml file format.
/// Save the applicatiion data into JSON file format.
/// </summary>
/// <typeparam name="T"> type of the data save. </typeparam>
/// <param name="filePath"> where to save. </param>
/// <param name="fileName"> name of the file u want to save. </param>
/// <param name="fileName"> name of the file you want to save. </param>
public override void Save<T>(string filePath, string fileName)
{
string fullFilePath = filePath + fileName;
Expand All @@ -38,11 +38,11 @@ public override void Save<T>(string filePath, string fileName)
}

/// <summary>
/// Save the game data into xml file format.
/// Save the applicatiion data into JSON file format.
/// </summary>
/// <typeparam name="T"> type of the data save. </typeparam>
/// <param name="filePath"> where to save. </param>
/// <param name="fileName"> name of the file u want to save. </param>
/// <param name="fileName"> name of the file you want to save. </param>
public override void Save<T>(string fullFilePath)
{
string filePath = Path.GetDirectoryName(fullFilePath);
Expand All @@ -53,20 +53,20 @@ public override void Save<T>(string fullFilePath)

using (var stream = new FileStream(fullFilePath, FileMode.Create))
{
string json = JsonUtility.ToJson(this);
string json = JsonConvert.SerializeObject(this);
byte[] info = new UTF8Encoding(true).GetBytes(json);
stream.Write(info, 0, info.Length);
}
}

/// <summary>
/// Load the game data from a directory file path.
/// Load the applicatiion data from a directory file path.
/// </summary>
/// <typeparam name="T"> type of the game data u want to load. </typeparam>
/// <typeparam name="T"> type of the applicatiion data you want to load. </typeparam>
/// <param name="filePath"> file directory, location, path. </param>
/// <param name="fileName"> name of the file u want to load. </param>
/// <param name="fileName"> name of the file you want to load. </param>
/// <returns>
/// Full game data. If the file does not exists returns
/// Full applicatiion data. If the file does not exists returns
/// null references.
/// </returns>
public static T LoadFromFile<T>(string filePath, string fileName)
Expand All @@ -77,12 +77,12 @@ public static T LoadFromFile<T>(string filePath, string fileName)
}

/// <summary>
/// Load the game data from a directory file path.
/// Load the applicatiion data from a directory file path.
/// </summary>
/// <typeparam name="T"> type of the game data u want to load. </typeparam>
/// <typeparam name="T"> type of the applicatiion data you want to load. </typeparam>
/// <param name="fullFilePath"> file path to the file. </param>
/// <returns>
/// Full game data. If the file does not exists returns
/// Full applicatiion data. If the file does not exists returns
/// null references.
/// </returns>
public static T LoadFromFile<T>(string fullFilePath)
Expand All @@ -97,7 +97,7 @@ public static T LoadFromFile<T>(string fullFilePath)
{
contents = sr.ReadToEnd();
}
return JsonUtility.FromJson<T>(contents);
return JsonConvert.DeserializeObject<T>(contents);
}
}
}
Expand Down
22 changes: 11 additions & 11 deletions Assets/JCSUnity/Scripts/SaveLoad/JCS_XMLData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ public abstract class JCS_XMLData : JCS_AppData
/* Functions */

/// <summary>
/// Save the game data into xml file format.
/// Save the applicatiion data into XML file format.
/// </summary>
/// <typeparam name="T"> type of the data save. </typeparam>
/// <param name="filePath"> where to save. </param>
/// <param name="fileName"> name of the file u want to save. </param>
/// <param name="fileName"> name of the file you want to save. </param>
public override void Save<T>(string filePath, string fileName)
{
string fullFilePath = filePath + fileName;
Expand All @@ -36,11 +36,11 @@ public override void Save<T>(string filePath, string fileName)
}

/// <summary>
/// Save the game data into xml file format.
/// Save the applicatiion data into XML file format.
/// </summary>
/// <typeparam name="T"> type of the data save. </typeparam>
/// <param name="filePath"> where to save. </param>
/// <param name="fileName"> name of the file u want to save. </param>
/// <param name="fileName"> name of the file you want to save. </param>
public override void Save<T>(string fullFilePath)
{
string filePath = Path.GetDirectoryName(fullFilePath);
Expand All @@ -57,13 +57,13 @@ public override void Save<T>(string fullFilePath)
}

/// <summary>
/// Load the game data from a directory file path.
/// Load the applicatiion data from a directory file path.
/// </summary>
/// <typeparam name="T"> type of the game data u want to load. </typeparam>
/// <typeparam name="T"> type of the applicatiion data you want to load. </typeparam>
/// <param name="filePath"> file directory, location, path. </param>
/// <param name="fileName"> name of the file u want to load. </param>
/// <param name="fileName"> name of the file you want to load. </param>
/// <returns>
/// Full game data. If the file does not exists returns
/// Full applicatiion data. If the file does not exists returns
/// null references.
/// </returns>
public static T LoadFromFile<T>(string filePath, string fileName)
Expand All @@ -74,12 +74,12 @@ public static T LoadFromFile<T>(string filePath, string fileName)
}

/// <summary>
/// Load the game data from a directory file path.
/// Load the applicatiion data from a directory file path.
/// </summary>
/// <typeparam name="T"> type of the game data u want to load. </typeparam>
/// <typeparam name="T"> type of the applicatiion data you want to load. </typeparam>
/// <param name="fullFilePath"> file path to the file. </param>
/// <returns>
/// Full game data. If the file does not exists returns
/// Full applicatiion data. If the file does not exists returns
/// null references.
/// </returns>
public static T LoadFromFile<T>(string fullFilePath)
Expand Down
7 changes: 4 additions & 3 deletions Packages/manifest.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"dependencies": {
"com.unity.ai.navigation": "2.0.4",
"com.unity.ai.navigation": "2.0.5",
"com.unity.collab-proxy": "2.5.2",
"com.unity.ide.rider": "3.0.31",
"com.unity.ide.rider": "3.0.34",
"com.unity.ide.visualstudio": "2.0.22",
"com.unity.multiplayer.center": "1.0.0",
"com.unity.nuget.newtonsoft-json": "3.2.1",
"com.unity.test-framework": "1.4.5",
"com.unity.timeline": "1.8.7",
"com.unity.toolchain.win-x86_64-linux-x86_64": "2.0.10",
"com.unity.ugui": "2.0.0",
"com.unity.visualscripting": "1.9.4",
"com.unity.visualscripting": "1.9.5",
"com.unity.modules.accessibility": "1.0.0",
"com.unity.modules.ai": "1.0.0",
"com.unity.modules.androidjni": "1.0.0",
Expand Down
13 changes: 10 additions & 3 deletions Packages/packages-lock.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"dependencies": {
"com.unity.ai.navigation": {
"version": "2.0.4",
"version": "2.0.5",
"depth": 0,
"source": "registry",
"dependencies": {
Expand All @@ -24,7 +24,7 @@
"url": "https://packages.unity.com"
},
"com.unity.ide.rider": {
"version": "3.0.31",
"version": "3.0.34",
"depth": 0,
"source": "registry",
"dependencies": {
Expand All @@ -49,6 +49,13 @@
"com.unity.modules.uielements": "1.0.0"
}
},
"com.unity.nuget.newtonsoft-json": {
"version": "3.2.1",
"depth": 0,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.com"
},
"com.unity.sysroot": {
"version": "2.0.10",
"depth": 1,
Expand Down Expand Up @@ -108,7 +115,7 @@
}
},
"com.unity.visualscripting": {
"version": "1.9.4",
"version": "1.9.5",
"depth": 0,
"source": "registry",
"dependencies": {
Expand Down
22 changes: 7 additions & 15 deletions ProjectSettings/PackageManagerSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,25 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_EnablePreReleasePackages: 0
m_EnablePackageDependencies: 0
m_AdvancedSettingsExpanded: 1
m_ScopedRegistriesSettingsExpanded: 1
m_SeeAllPackageVersions: 0
m_DismissPreviewPackagesInUse: 0
oneTimeWarningShown: 0
oneTimeDeprecatedPopUpShown: 0
m_Registries:
- m_Id: main
m_Name:
m_Url: https://packages.unity.com
m_Scopes: []
m_IsDefault: 1
m_Capabilities: 7
m_ConfigSource: 0
m_UserSelectedRegistryName:
m_UserAddingNewScopedRegistry: 0
m_RegistryInfoDraft:
m_ErrorMessage:
m_Original:
m_Id:
m_Name:
m_Url:
m_Scopes: []
m_IsDefault: 0
m_Capabilities: 0
m_Modified: 0
m_Name:
m_Url:
m_Scopes:
-
m_SelectedScopeIndex: 0
m_LoadAssets: 0
m_ErrorMessage:
m_UserModificationsInstanceId: -866
m_OriginalInstanceId: -868
m_LoadAssets: -1
18 changes: 12 additions & 6 deletions ProjectSettings/ProjectSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ PlayerSettings:
m_StereoRenderingPath: 0
m_ActiveColorSpace: 0
unsupportedMSAAFallback: 0
m_SpriteBatchMaxVertexCount: 65535
m_SpriteBatchVertexThreshold: 300
m_MTRendering: 1
mipStripping: 0
Expand Down Expand Up @@ -77,12 +78,11 @@ PlayerSettings:
androidMinimumWindowHeight: 300
androidFullscreenMode: 1
androidAutoRotationBehavior: 1
androidApplicationEntry: 1
androidPredictiveBackSupport: 0
androidApplicationEntry: 1
defaultIsNativeResolution: 1
macRetinaSupport: 1
runInBackground: 1
captureSingleScreen: 1
muteOtherAudioSources: 0
Prepare IOS For Recording: 0
Force IOS Speakers When Recording: 0
Expand Down Expand Up @@ -488,7 +488,10 @@ PlayerSettings:
m_Height: 1024
m_Kind: 4
m_SubKind: App Store
m_BuildTargetBatching: []
m_BuildTargetBatching:
- m_BuildTarget: Standalone
m_StaticBatching: 1
m_DynamicBatching: 1
m_BuildTargetShaderSettings: []
m_BuildTargetGraphicsJobs:
- m_BuildTarget: MacStandaloneSupport
Expand Down Expand Up @@ -597,7 +600,7 @@ PlayerSettings:
m_BuildTargetGroupLightmapEncodingQuality:
- serializedVersion: 2
m_BuildTarget: Standalone
m_EncodingQuality: 1
m_EncodingQuality: 2
- serializedVersion: 2
m_BuildTarget: XboxOne
m_EncodingQuality: 1
Expand All @@ -611,6 +614,7 @@ PlayerSettings:
playModeTestRunnerEnabled: 0
runPlayModeTestAsEditModeTest: 0
actionOnDotNetUnhandledException: 1
editorGfxJobOverride: 1
enableInternalProfiler: 0
logObjCUncaughtExceptions: 1
enableCrashReportAPI: 0
Expand Down Expand Up @@ -903,8 +907,8 @@ PlayerSettings:
gcWBarrierValidation: 0
apiCompatibilityLevelPerPlatform:
Android: 3
Standalone: 3
editorAssembliesCompatibilityLevel: 1
Standalone: 6
editorAssembliesCompatibilityLevel: 2
m_RenderingPath: 1
m_MobileRenderingPath: 1
metroPackageName: JCSUnityFramework
Expand Down Expand Up @@ -1006,3 +1010,5 @@ PlayerSettings:
platformRequiresReadableAssets: 0
virtualTexturingSupportEnabled: 0
insecureHttpOption: 0
androidVulkanDenyFilterList: []
androidVulkanAllowFilterList: []
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ directory at the root of the project directory.

## 📌 Dependencies

These are libraries `JCSUnity` uses. Consider the usage, some plugins
aren't necessary depend on the game your are making.
These are libraries `JCSUnity` uses. Consider the usage, some plugins aren't necessary
depend on the game your are making.

- [Newtonsoft Json](https://www.newtonsoft.com/json) - Popular high-performance JSON framework for .NET.
- [MyBox](https://github.com/Deadcows/MyBox) - is a set of attributes, tools and extensions for Unity
- [Tweener](https://github.com/PeterVuorela/Tweener) - Simpler and light weight tweener library.
- [In-game Debug Console](https://assetstore.unity.com/packages/tools/gui/in-game-debug-console-68068) - Easier debugging after built.
Expand Down

0 comments on commit f372c90

Please sign in to comment.