|
- 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[] allBundles;
-
- public static bool Init()
- {
- allBundles = AssetBundle.GetAllLoadedAssetBundles().ToArray();
- string[] allBundleNames = new string[allBundles.Length];
- for (int i = 0; i < allBundles.Length; i++)
- {
- allBundleNames[i] = allBundles[i].name;
- }
- Debug.Log($"Dissonance: Found AssetBundle {string.Join(", ", allBundleNames)}");
- return allBundles != 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 Log<T>(AssetBundle assetBundle) where T : UnityEngine.Object
- {
- Instance[] instances = Inspect<T>(assetBundle);
- 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 LogNames<T>(AssetBundle assetBundle) where T : UnityEngine.Object
- {
- Debug.Log(string.Join("\n", InspectNames<T>(assetBundle)));
- }
-
- 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 Dump<T>(string filename, AssetBundle assetBundle) where T : UnityEngine.Object
- {
- Instance[] instances = Inspect<T>(assetBundle);
- 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 DumpNames<T>(string filename, AssetBundle assetBundle) where T : UnityEngine.Object
- {
- File.WriteAllLines(filename, InspectNames<T>(assetBundle));
- }
-
- public static void DumpNamesAll(string filename)
- {
- DumpNames<UnityEngine.Object>(filename);
- }
-
- public static void DumpNamesAll(string filename, AssetBundle assetBundle)
- {
- DumpNames<UnityEngine.Object>(filename, assetBundle);
- }
-
- public static Instance[] Inspect<T>() where T : UnityEngine.Object
- {
- if (allBundles == null) Init();
- List<Instance> allInstances = new List<Instance>();
- foreach (var b in allBundles)
- {
- allInstances.AddRange(Inspect<T>(b));
- }
- return allInstances.ToArray();
- }
-
- public static Instance[] Inspect<T>(AssetBundle assetBundle) where T : UnityEngine.Object
- {
- List<Instance> allInstances = new List<Instance>();
- UnityEngine.Object[] assets = assetBundle.LoadAllAssets<T>();
- for (int i = 0; i < assets.Length; i++)
- {
- allInstances.Add(new Instance(assets[i]));
- }
- return allInstances.ToArray();
- }
-
- public static string[] InspectNames<T>() where T : UnityEngine.Object
- {
- if (allBundles == null) Init();
- List<string> allNames = new List<string>();
- foreach (var b in allBundles)
- {
- allNames.AddRange(InspectNames<T>(b));
- }
- return allNames.ToArray();
- }
-
- public static string[] InspectNames<T>(AssetBundle assetBundle) where T : UnityEngine.Object
- {
- List<string> allNames = new List<string>();
- UnityEngine.Object[] assets = assetBundle.LoadAllAssets<T>();
- for (int i = 0; i < assets.Length; i++)
- {
- allNames.Add(assets[i].name);
- }
- return allNames.ToArray();
- }
- }
- }
|