Improve detection of Live2D models. Close #122

- Added an alternative way of model detection when a MonoScript asset is not loaded.
- Fixed model detection regression after the https://github.com/aelurum/AssetStudio/commit/0066d673f45cfd07bbca4343e2fdf27660698c17
This commit is contained in:
VaDiM
2026-07-07 17:35:03 +03:00
parent 9a6ceeb144
commit b51a5bbdf6
10 changed files with 371 additions and 130 deletions
@@ -6,12 +6,12 @@ using static CubismLive2DExtractor.CubismParsers;
namespace AssetStudioGUI
{
public class L2DAssetManager
public class L2DAssetsManager
{
public readonly Dictionary<MonoBehaviour, CubismModel> ModelDict = new Dictionary<MonoBehaviour, CubismModel>();
public readonly Dictionary<Object, string> AssetContainers = new Dictionary<Object, string>();
public L2DAssetManager () { }
public L2DAssetsManager () { }
public void BindCubismAssetsByGO(GameObject m_GameObject, AssemblyLoader assemblyLoader)
{
@@ -32,12 +32,6 @@ namespace AssetStudioGUI
switch (m_ClassName)
{
case "CubismMoc":
if (!ModelDict.ContainsKey(m_MonoBehaviour))
{
ModelDict.Add(m_MonoBehaviour, null);
}
break;
case "CubismRenderer":
modelGameObject.CubismModel.RenderTextureList.Add(m_MonoBehaviour);
break;
@@ -53,10 +47,29 @@ namespace AssetStudioGUI
}
}
public void BindCubismAssetsByMono(MonoBehaviour m_MonoBehaviour, CubismHelpers.CubismMonoBehaviourType type)
{
if (!m_MonoBehaviour.m_GameObject.TryGet(out var m_GameObject))
return;
if (!TryGetModelGameObject(m_GameObject.m_Transform, out var modelGameObject))
return;
switch (type)
{
case CubismHelpers.CubismMonoBehaviourType.RenderTexture:
modelGameObject.CubismModel.RenderTextureList.Add(m_MonoBehaviour);
break;
case CubismHelpers.CubismMonoBehaviourType.PosePart:
modelGameObject.CubismModel.PosePartList.Add(m_MonoBehaviour);
break;
}
}
private static bool TryGetCubismMoc(MonoBehaviour m_MonoBehaviour, AssemblyLoader assemblyLoader, out MonoBehaviour mocMono)
{
mocMono = null;
var pptrDict = (OrderedDictionary)ParseMonoBehaviour(m_MonoBehaviour, CubismMonoBehaviourType.Model, assemblyLoader)?["_moc"];
var pptrDict = (OrderedDictionary)ParseMonoBehaviour(m_MonoBehaviour, CubismHelpers.CubismMonoBehaviourType.ModelPPtr, assemblyLoader)?["_moc"];
if (pptrDict == null)
return false;