Adding MonoBehaviour Atlas Type Handler

This commit is contained in:
15459 2023-10-30 00:23:17 +08:00
parent fc2b4d8ad6
commit 4d99595788
3 changed files with 44 additions and 15 deletions

View File

@ -1029,13 +1029,22 @@ namespace AssetStudioGUI
private void PreviewMonoBehaviour(MonoBehaviour m_MonoBehaviour)
{
var obj = m_MonoBehaviour.ToType();
if (obj == null)
String str;
String name = m_MonoBehaviour.m_Name;
if (!name.EndsWith("Atlas"))
{
var type = MonoBehaviourToTypeTree(m_MonoBehaviour);
obj = m_MonoBehaviour.ToType(type);
var obj = m_MonoBehaviour.ToType();
if (obj == null)
{
var type = MonoBehaviourToTypeTree(m_MonoBehaviour);
obj = m_MonoBehaviour.ToType(type);
}
str = JsonConvert.SerializeObject(obj, Formatting.Indented);
}
else
{
str = "ATLAS资源暂时无法预览";
}
var str = JsonConvert.SerializeObject(obj, Formatting.Indented);
PreviewText(str);
}

View File

@ -93,17 +93,31 @@ namespace AssetStudioGUI
public static bool ExportMonoBehaviour(AssetItem item, string exportPath)
{
if (!TryExportFile(exportPath, item, ".json", out var exportFullPath))
return false;
var m_MonoBehaviour = (MonoBehaviour)item.Asset;
var type = m_MonoBehaviour.ToType();
if (type == null)
String name = m_MonoBehaviour.m_Name;
if (name.EndsWith("_Atlas"))
{
var m_Type = Studio.MonoBehaviourToTypeTree(m_MonoBehaviour);
type = m_MonoBehaviour.ToType(m_Type);
if (!TryExportFile(exportPath, item, ".atlas", out var exportFullPath))
return false;
String data = System.Text.Encoding.UTF8.GetString(m_MonoBehaviour.GetRawData());
String split_identify = name.Replace("_Atlas", ".png");
// TODO 使用FOR循环列表切片
String rawAtlasData = split_identify + data.Split(split_identify)[1];
File.WriteAllText(exportFullPath, rawAtlasData);
}
else
{
if (!TryExportFile(exportPath, item, ".json", out var exportFullPath))
return false;
var type = m_MonoBehaviour.ToType();
if (type == null)
{
var m_Type = Studio.MonoBehaviourToTypeTree(m_MonoBehaviour);
type = m_MonoBehaviour.ToType(m_Type);
}
var str = JsonConvert.SerializeObject(type, Formatting.Indented);
File.WriteAllText(exportFullPath, str);
}
var str = JsonConvert.SerializeObject(type, Formatting.Indented);
File.WriteAllText(exportFullPath, str);
return true;
}

View File

@ -976,8 +976,14 @@ namespace AssetStudioGUI
var str = obj.Dump();
if (str == null && obj is MonoBehaviour m_MonoBehaviour)
{
var type = MonoBehaviourToTypeTree(m_MonoBehaviour);
str = m_MonoBehaviour.Dump(type);
if (m_MonoBehaviour.m_Name.EndsWith("_Atlas"))
{
str = "ATLAS格式暂时无法Dump";
}
else {
var type = MonoBehaviourToTypeTree(m_MonoBehaviour);
str = m_MonoBehaviour.Dump(type);
}
}
return str;
}