Skip to content

Commit 18dc6df

Browse files
committed
add bundle support to getdependency
(and other dependency improvements)
1 parent c64d8f2 commit 18dc6df

4 files changed

Lines changed: 52 additions & 22 deletions

File tree

AssetTools.NET/Extra/AssetsManager/AssetsFileInstance.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ public AssetsFileInstance GetDependency(AssetsManager am, int depIdx)
5151
int instIndex = am.files.FindIndex(f => Path.GetFileName(f.path).ToLower() == Path.GetFileName(depPath).ToLower());
5252
if (instIndex == -1)
5353
{
54-
string absPath = Path.Combine(path, depPath);
55-
string localAbsPath = Path.Combine(path, Path.GetFileName(depPath));
54+
string pathDir = Path.GetDirectoryName(path);
55+
string absPath = Path.Combine(pathDir, depPath);
56+
string localAbsPath = Path.Combine(pathDir, Path.GetFileName(depPath));
5657
if (File.Exists(absPath))
5758
{
5859
dependencies[depIdx] = am.LoadAssetsFile(File.OpenRead(absPath), true);
@@ -61,6 +62,14 @@ public AssetsFileInstance GetDependency(AssetsManager am, int depIdx)
6162
{
6263
dependencies[depIdx] = am.LoadAssetsFile(File.OpenRead(localAbsPath), true);
6364
}
65+
else if (parentBundle != null)
66+
{
67+
dependencies[depIdx] = am.LoadAssetsFileFromBundle(parentBundle, depPath, true);
68+
}
69+
else
70+
{
71+
return null;
72+
}
6473
}
6574
else
6675
{

AssetTools.NET/Extra/AssetsManager/AssetsManager.cs

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public AssetsFileInstance LoadAssetsFile(Stream stream, string path, bool loadDe
2727
if (index == -1)
2828
{
2929
instance = new AssetsFileInstance(stream, path, root);
30+
instance.parentBundle = bunInst;
3031
files.Add(instance);
3132
}
3233
else
@@ -289,33 +290,52 @@ public void LoadBundleDependencies(AssetsFileInstance ofFile, BundleFileInstance
289290
#region asset resolving
290291
public AssetExternal GetExtAsset(AssetsFileInstance relativeTo, int fileId, long pathId, bool onlyGetInfo = false, bool forceFromCldb = false)
291292
{
292-
AssetExternal ext = new AssetExternal();
293+
AssetExternal ext = new AssetExternal
294+
{
295+
info = null,
296+
instance = null,
297+
file = null
298+
};
299+
293300
if (fileId == 0 && pathId == 0)
294301
{
295-
ext.info = null;
296-
ext.instance = null;
297-
ext.file = null;
302+
return ext;
298303
}
299304
else if (fileId != 0)
300305
{
301306
AssetsFileInstance dep = relativeTo.GetDependency(this, fileId - 1);
307+
308+
if (dep == null)
309+
return ext;
310+
302311
ext.info = dep.table.GetAssetInfo(pathId);
312+
313+
if (ext.info == null)
314+
return ext;
315+
303316
if (!onlyGetInfo)
304317
ext.instance = GetTypeInstance(dep.file, ext.info, forceFromCldb);
305318
else
306319
ext.instance = null;
320+
307321
ext.file = dep;
322+
return ext;
308323
}
309324
else
310325
{
311326
ext.info = relativeTo.table.GetAssetInfo(pathId);
327+
328+
if (ext.info == null)
329+
return ext;
330+
312331
if (!onlyGetInfo)
313332
ext.instance = GetTypeInstance(relativeTo.file, ext.info, forceFromCldb);
314333
else
315334
ext.instance = null;
335+
316336
ext.file = relativeTo;
337+
return ext;
317338
}
318-
return ext;
319339
}
320340

321341
public AssetExternal GetExtAsset(AssetsFileInstance relativeTo, AssetTypeValueField atvf, bool onlyGetInfo = false, bool forceFromCldb = false)
@@ -389,11 +409,16 @@ public AssetTypeValueField GetMonoBaseFieldCached(AssetsFileInstance inst, Asset
389409
if (!inst.monoIdToName.ContainsKey(scriptIndex))
390410
{
391411
AssetTypeInstance scriptAti = GetExtAsset(inst, GetTypeInstance(inst.file, info).GetBaseField().Get("m_Script")).instance;
412+
413+
//couldn't find asset
414+
if (scriptAti == null)
415+
return null;
416+
392417
scriptName = scriptAti.GetBaseField().Get("m_Name").GetValue().AsString();
393418
string scriptNamespace = scriptAti.GetBaseField().Get("m_Namespace").GetValue().AsString();
394419
string assemblyName = scriptAti.GetBaseField().Get("m_AssemblyName").GetValue().AsString();
395420

396-
if (scriptNamespace != string.Empty)
421+
if (scriptNamespace == string.Empty)
397422
{
398423
scriptNamespace = "-";
399424
}

AssetsView/Winforms/GameObjectViewer.cs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using AssetsTools.NET.Extra;
33
using AssetsView.Util;
44
using System;
5-
//using System.Data.Entity.Design.PluralizationServices;
65
using System.Drawing;
76
using System.Globalization;
87
using System.IO;
@@ -17,7 +16,6 @@ public partial class GameObjectViewer : Form
1716
private AssetsFileInstance inst;
1817
private long selectedId;
1918
private long selectedGameObjectId;
20-
private bool firstTimeMBMessage;
2119
public GameObjectViewer(AssetsManager helper, AssetsFileInstance inst, long selectedId)
2220
{
2321
InitializeComponent();
@@ -169,19 +167,11 @@ private void LoadComponentData(PGProperty root, AssetTypeValueField baseField, A
169167
AssetTypeValueField targetBaseField = baseField;
170168
if (className == "MonoBehaviour")
171169
{
172-
if (AssetUtils.AllDependenciesLoaded(helper, inst))
170+
className += $" ({GetClassName(helper, inst, targetBaseField)})";
171+
string managedPath = Path.Combine(Path.GetDirectoryName(inst.path), "Managed");
172+
if (Directory.Exists(managedPath))
173173
{
174-
className += $" ({GetClassName(helper, inst, targetBaseField)})";
175-
string managedPath = Path.Combine(Path.GetDirectoryName(inst.path), "Managed");
176-
if (Directory.Exists(managedPath))
177-
{
178-
targetBaseField = helper.GetMonoBaseFieldCached(inst, info, managedPath);
179-
}
180-
}
181-
else if (!firstTimeMBMessage)
182-
{
183-
firstTimeMBMessage = true;
184-
MessageBox.Show("Can't display MonoBehaviour data until dependencies are loaded", "Assets View");
174+
targetBaseField = helper.GetMonoBaseFieldCached(inst, info, managedPath);
185175
}
186176
}
187177
string category = new string('\t', size - index) + className;

AssetsView/Winforms/StartScreen.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,12 @@ public void OpenAsset(long id)
522522
{
523523
GameObjectViewer view = new GameObjectViewer(helper, currentFile, id);
524524
view.Show();
525+
view.FormClosed += GameObjectViewer_FormClosed;
526+
}
527+
528+
private void GameObjectViewer_FormClosed(object sender, FormClosedEventArgs e)
529+
{
530+
UpdateFileList();
525531
}
526532

527533
private void RecurseForResourcesInfo(FSDirectory dir, AssetsFileInstance afi)

0 commit comments

Comments
 (0)