|
|
@@ -0,0 +1,103 @@ |
|
|
|
using System; |
|
|
|
using System.IO; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using System.Text; |
|
|
|
using UnityEngine; |
|
|
|
|
|
|
|
namespace Dissonance.Inspector |
|
|
|
{ |
|
|
|
public static class AssetInspector |
|
|
|
{ |
|
|
|
private static AssetBundle bundle; |
|
|
|
|
|
|
|
public static bool Init() |
|
|
|
{ |
|
|
|
foreach(AssetBundle ab in AssetBundle.GetAllLoadedAssetBundles()) |
|
|
|
{ |
|
|
|
if (ab != null) |
|
|
|
{ |
|
|
|
bundle = ab; |
|
|
|
} |
|
|
|
} |
|
|
|
Debug.Log($"Dissonance: Found AssetBundle {bundle.name}"); |
|
|
|
return bundle != null; |
|
|
|
} |
|
|
|
|
|
|
|
public static void Log<T>() where T : UnityEngine.Object |
|
|
|
{ |
|
|
|
Instance[] instances = Inspect<T>(); |
|
|
|
string[] filelines = new string[instances.Length]; |
|
|
|
for (int i = 0; i < instances.Length; i++) |
|
|
|
{ |
|
|
|
filelines[i] = instances[i].ToString() + ","; |
|
|
|
} |
|
|
|
Debug.Log("AssetInspector Log dump\n[" + string.Join(",\n", filelines) + "]"); |
|
|
|
} |
|
|
|
|
|
|
|
public static void LogNames<T>() where T : UnityEngine.Object |
|
|
|
{ |
|
|
|
Debug.Log(string.Join("\n", InspectNames<T>())); |
|
|
|
} |
|
|
|
|
|
|
|
public static void LogAll() |
|
|
|
{ |
|
|
|
Log<UnityEngine.Object>(); |
|
|
|
} |
|
|
|
|
|
|
|
public static void LogNamesAll() |
|
|
|
{ |
|
|
|
LogNames<UnityEngine.Object>(); |
|
|
|
} |
|
|
|
|
|
|
|
public static void Dump<T>(string filename) where T : UnityEngine.Object |
|
|
|
{ |
|
|
|
Instance[] instances = Inspect<T>(); |
|
|
|
string[] filelines = new string[instances.Length]; |
|
|
|
for (int i = 0; i < instances.Length; i++) |
|
|
|
{ |
|
|
|
filelines[i] = instances[i].ToString() + ","; |
|
|
|
} |
|
|
|
File.WriteAllLines(filename, filelines); |
|
|
|
} |
|
|
|
|
|
|
|
public static void DumpNames<T>(string filename) where T : UnityEngine.Object |
|
|
|
{ |
|
|
|
File.WriteAllLines(filename, InspectNames<T>()); |
|
|
|
} |
|
|
|
|
|
|
|
public static void DumpAll(string filename) |
|
|
|
{ |
|
|
|
Dump<UnityEngine.Object>(filename); |
|
|
|
} |
|
|
|
|
|
|
|
public static void DumpNamesAll(string filename) |
|
|
|
{ |
|
|
|
DumpNames<UnityEngine.Object>(filename); |
|
|
|
} |
|
|
|
|
|
|
|
public static Instance[] Inspect<T>() where T : UnityEngine.Object |
|
|
|
{ |
|
|
|
if (bundle == null) Init(); |
|
|
|
UnityEngine.Object[] assets = bundle.LoadAllAssets<T>(); |
|
|
|
Instance[] instances = new Instance[assets.Length]; |
|
|
|
for (int i = 0; i < assets.Length; i++) |
|
|
|
{ |
|
|
|
instances[i] = new Instance(assets[i]); |
|
|
|
} |
|
|
|
return instances; |
|
|
|
} |
|
|
|
|
|
|
|
public static string[] InspectNames<T>() where T : UnityEngine.Object |
|
|
|
{ |
|
|
|
if (bundle == null) Init(); |
|
|
|
UnityEngine.Object[] assets = bundle.LoadAllAssets<T>(); |
|
|
|
string[] names = new string[assets.Length]; |
|
|
|
for (int i = 0; i < assets.Length; i++) |
|
|
|
{ |
|
|
|
names[i] = assets[i].name; |
|
|
|
} |
|
|
|
return names; |
|
|
|
} |
|
|
|
} |
|
|
|
} |