mirror of
https://github.com/aelurum/AssetStudio.git
synced 2025-07-14 02:54:16 -04:00
Support exporting MonoBehaviour to json. Close #477
This commit is contained in:
@ -39,6 +39,9 @@
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="OpenTK, Version=3.1.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\OpenTK.3.1.0\lib\net20\OpenTK.dll</HintPath>
|
||||
</Reference>
|
||||
|
@ -1,4 +1,5 @@
|
||||
using AssetStudio;
|
||||
using Newtonsoft.Json;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
using System;
|
||||
@ -930,7 +931,14 @@ namespace AssetStudioGUI
|
||||
|
||||
private void PreviewMonoBehaviour(MonoBehaviour m_MonoBehaviour)
|
||||
{
|
||||
PreviewText(m_MonoBehaviour.Dump() ?? DeserializeMonoBehaviour(m_MonoBehaviour));
|
||||
var obj = m_MonoBehaviour.ToType();
|
||||
if (obj == null)
|
||||
{
|
||||
var nodes = MonoBehaviourToTypeTreeNodes(m_MonoBehaviour);
|
||||
obj = m_MonoBehaviour.ToType(nodes);
|
||||
}
|
||||
var str = JsonConvert.SerializeObject(obj, Formatting.Indented);
|
||||
PreviewText(str);
|
||||
}
|
||||
|
||||
private void PreviewFont(Font m_Font)
|
||||
|
@ -4,6 +4,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using AssetStudio;
|
||||
using Newtonsoft.Json;
|
||||
using TGASharpLib;
|
||||
|
||||
namespace AssetStudioGUI
|
||||
@ -113,10 +114,16 @@ namespace AssetStudioGUI
|
||||
|
||||
public static bool ExportMonoBehaviour(AssetItem item, string exportPath)
|
||||
{
|
||||
if (!TryExportFile(exportPath, item, ".txt", out var exportFullPath))
|
||||
if (!TryExportFile(exportPath, item, ".json", out var exportFullPath))
|
||||
return false;
|
||||
var m_MonoBehaviour = (MonoBehaviour)item.Asset;
|
||||
var str = m_MonoBehaviour.Dump() ?? Studio.DeserializeMonoBehaviour(m_MonoBehaviour);
|
||||
var type = m_MonoBehaviour.ToType();
|
||||
if (type == null)
|
||||
{
|
||||
var nodes = Studio.MonoBehaviourToTypeTreeNodes(m_MonoBehaviour);
|
||||
type = m_MonoBehaviour.ToType(nodes);
|
||||
}
|
||||
var str = JsonConvert.SerializeObject(type, Formatting.Indented);
|
||||
File.WriteAllText(exportFullPath, str);
|
||||
return true;
|
||||
}
|
||||
@ -358,6 +365,11 @@ namespace AssetStudioGUI
|
||||
if (!TryExportFile(exportPath, item, ".txt", out var exportFullPath))
|
||||
return false;
|
||||
var str = item.Asset.Dump();
|
||||
if (str == null && item.Asset is MonoBehaviour m_MonoBehaviour)
|
||||
{
|
||||
var nodes = Studio.MonoBehaviourToTypeTreeNodes(m_MonoBehaviour);
|
||||
str = m_MonoBehaviour.Dump(nodes);
|
||||
}
|
||||
if (str != null)
|
||||
{
|
||||
File.WriteAllText(exportFullPath, str);
|
||||
|
@ -615,7 +615,7 @@ namespace AssetStudioGUI
|
||||
}
|
||||
}
|
||||
|
||||
public static string DeserializeMonoBehaviour(MonoBehaviour m_MonoBehaviour)
|
||||
public static List<TypeTreeNode> MonoBehaviourToTypeTreeNodes(MonoBehaviour m_MonoBehaviour)
|
||||
{
|
||||
if (!assemblyLoader.Loaded)
|
||||
{
|
||||
@ -630,14 +630,7 @@ namespace AssetStudioGUI
|
||||
assemblyLoader.Loaded = true;
|
||||
}
|
||||
}
|
||||
var nodes = m_MonoBehaviour.ConvertToTypeTreeNode(assemblyLoader);
|
||||
if (nodes != null)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
TypeTreeHelper.ReadTypeString(sb, nodes, m_MonoBehaviour.reader);
|
||||
return sb.ToString();
|
||||
}
|
||||
return null;
|
||||
return m_MonoBehaviour.ConvertToTypeTreeNodes(assemblyLoader);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Newtonsoft.Json" version="12.0.3" targetFramework="net472" />
|
||||
<package id="OpenTK" version="3.1.0" targetFramework="net472" />
|
||||
<package id="OpenTK.GLControl" version="3.1.0" targetFramework="net472" />
|
||||
</packages>
|
Reference in New Issue
Block a user