mirror of
https://github.com/aelurum/AssetStudio.git
synced 2026-11-17 03:38:48 -05:00
Replace Newtonsoft.Json with System.Text.Json for MonoBehaviour assets
This commit is contained in:
@@ -8,6 +8,7 @@ namespace AssetStudio
|
|||||||
{
|
{
|
||||||
public class Object
|
public class Object
|
||||||
{
|
{
|
||||||
|
public static readonly JsonSerializerOptions JsonOptions;
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public SerializedFile assetsFile;
|
public SerializedFile assetsFile;
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
@@ -25,11 +26,10 @@ namespace AssetStudio
|
|||||||
public uint byteSize;
|
public uint byteSize;
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public string Name;
|
public string Name;
|
||||||
private static readonly JsonSerializerOptions jsonOptions;
|
|
||||||
|
|
||||||
static Object()
|
static Object()
|
||||||
{
|
{
|
||||||
jsonOptions = new JsonSerializerOptions
|
JsonOptions = new JsonSerializerOptions
|
||||||
{
|
{
|
||||||
Converters = { new JsonConverterHelper.FloatConverter() },
|
Converters = { new JsonConverterHelper.FloatConverter() },
|
||||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
||||||
@@ -72,8 +72,8 @@ namespace AssetStudio
|
|||||||
m_Mesh.ProcessData();
|
m_Mesh.ProcessData();
|
||||||
}
|
}
|
||||||
|
|
||||||
str = JsonSerializer.Deserialize<JsonObject>(JsonSerializer.SerializeToUtf8Bytes(this, GetType(), jsonOptions))
|
str = JsonSerializer.Deserialize<JsonObject>(JsonSerializer.SerializeToUtf8Bytes(this, GetType(), JsonOptions))
|
||||||
.ToJsonString(jsonOptions).Replace(" ", " ");
|
.ToJsonString(JsonOptions).Replace(" ", " ");
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
@@ -108,7 +108,7 @@ namespace AssetStudio
|
|||||||
{
|
{
|
||||||
if (typeDict != null)
|
if (typeDict != null)
|
||||||
{
|
{
|
||||||
return JsonSerializer.SerializeToDocument(typeDict, jsonOptions);
|
return JsonSerializer.SerializeToDocument(typeDict, JsonOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this is Mesh m_Mesh)
|
if (this is Mesh m_Mesh)
|
||||||
@@ -116,7 +116,7 @@ namespace AssetStudio
|
|||||||
m_Mesh.ProcessData();
|
m_Mesh.ProcessData();
|
||||||
}
|
}
|
||||||
|
|
||||||
return JsonSerializer.SerializeToDocument(this, GetType(), jsonOptions);
|
return JsonSerializer.SerializeToDocument(this, GetType(), JsonOptions);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,10 +11,6 @@
|
|||||||
<DebugType>embedded</DebugType>
|
<DebugType>embedded</DebugType>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\AssetStudioUtility\AssetStudioUtility.csproj" />
|
<ProjectReference Include="..\AssetStudioUtility\AssetStudioUtility.csproj" />
|
||||||
<ProjectReference Include="..\AssetStudio\AssetStudio.csproj" />
|
<ProjectReference Include="..\AssetStudio\AssetStudio.csproj" />
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
using AssetStudio;
|
using AssetStudio;
|
||||||
using AssetStudioCLI.Options;
|
using AssetStudioCLI.Options;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -143,7 +142,7 @@ namespace AssetStudioCLI
|
|||||||
}
|
}
|
||||||
if (type != null)
|
if (type != null)
|
||||||
{
|
{
|
||||||
var str = JsonConvert.SerializeObject(type, Formatting.Indented);
|
var str = System.Text.Json.JsonSerializer.Serialize(type, Object.JsonOptions);
|
||||||
File.WriteAllText(exportFullPath, str);
|
File.WriteAllText(exportFullPath, str);
|
||||||
|
|
||||||
Logger.Debug($"{item.TypeString} \"{item.Text}\" exported to \"{exportFullPath}\"");
|
Logger.Debug($"{item.TypeString} \"{item.Text}\" exported to \"{exportFullPath}\"");
|
||||||
|
|||||||
@@ -60,7 +60,6 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft-WindowsAPICodePack-Core-6.0" Version="1.1.7" />
|
<PackageReference Include="Microsoft-WindowsAPICodePack-Core-6.0" Version="1.1.7" />
|
||||||
<PackageReference Include="Microsoft-WindowsAPICodePack-Shell-6.0" Version="1.1.7" />
|
<PackageReference Include="Microsoft-WindowsAPICodePack-Shell-6.0" Version="1.1.7" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup Condition=" '$(TargetFramework)' != 'net472' ">
|
<ItemGroup Condition=" '$(TargetFramework)' != 'net472' ">
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using AssetStudio;
|
using AssetStudio;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using OpenTK.Graphics.OpenGL;
|
using OpenTK.Graphics.OpenGL;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -1259,7 +1258,7 @@ namespace AssetStudioGUI
|
|||||||
var type = MonoBehaviourToTypeTree(m_MonoBehaviour);
|
var type = MonoBehaviourToTypeTree(m_MonoBehaviour);
|
||||||
obj = m_MonoBehaviour.ToType(type);
|
obj = m_MonoBehaviour.ToType(type);
|
||||||
}
|
}
|
||||||
var str = JsonConvert.SerializeObject(obj, Formatting.Indented);
|
var str = System.Text.Json.JsonSerializer.Serialize(obj, AssetStudio.Object.JsonOptions);
|
||||||
PreviewText(str);
|
PreviewText(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using AssetStudio;
|
using AssetStudio;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -121,7 +120,7 @@ namespace AssetStudioGUI
|
|||||||
var m_Type = Studio.MonoBehaviourToTypeTree(m_MonoBehaviour);
|
var m_Type = Studio.MonoBehaviourToTypeTree(m_MonoBehaviour);
|
||||||
type = m_MonoBehaviour.ToType(m_Type);
|
type = m_MonoBehaviour.ToType(m_Type);
|
||||||
}
|
}
|
||||||
var str = JsonConvert.SerializeObject(type, Formatting.Indented);
|
var str = System.Text.Json.JsonSerializer.Serialize(type, Object.JsonOptions);
|
||||||
File.WriteAllText(exportFullPath, str);
|
File.WriteAllText(exportFullPath, str);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user