diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportBundleInfo.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportBundleInfo.cs index b1e941a..862114d 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportBundleInfo.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportBundleInfo.cs @@ -8,6 +8,21 @@ namespace YooAsset.Editor [Serializable] public class ReportBundleInfo { + public class FlagsData + { + public bool IsEncrypted { private set; get; } + public bool IsBuildin { private set; get; } + public bool IsRawFile { private set; get; } + public FlagsData(bool isEncrypted, bool isBuildin, bool isRawFile) + { + IsEncrypted = isEncrypted; + IsBuildin = isBuildin; + IsRawFile = isRawFile; + } + } + + private FlagsData _flagData; + /// /// 资源包名称 /// @@ -38,6 +53,26 @@ namespace YooAsset.Editor /// public int Flags; + + /// + /// 获取标志位的解析数据 + /// + public FlagsData GetFlagData() + { + if (_flagData == null) + { + BitMask32 value = Flags; + bool isEncrypted = value.Test(0); + bool isBuildin = value.Test(1); + bool isRawFile = value.Test(2); + _flagData = new FlagsData(isEncrypted, isBuildin, isRawFile); + } + return _flagData; + } + + /// + /// 获取资源分类标签的字符串 + /// public string GetTagsString() { if (Tags != null) @@ -45,5 +80,16 @@ namespace YooAsset.Editor else return string.Empty; } + + /// + /// 是否为原生文件 + /// + public bool IsRawFile() + { + if (System.IO.Path.GetExtension(BundleName) == $".{YooAssetSettingsData.Setting.RawFileVariant}") + return true; + else + return false; + } } } \ No newline at end of file diff --git a/Assets/YooAsset/Editor/AssetBundleReporter/AssetBundleInspector.cs b/Assets/YooAsset/Editor/AssetBundleReporter/AssetBundleInspector.cs new file mode 100644 index 0000000..85a1bf2 --- /dev/null +++ b/Assets/YooAsset/Editor/AssetBundleReporter/AssetBundleInspector.cs @@ -0,0 +1,46 @@ +using System.IO; +using UnityEditor; +using UnityEngine; + +namespace YooAsset.Editor +{ + public class AssetBundleInspector + { + [CustomEditor(typeof(AssetBundle))] + internal class AssetBundleEditor : UnityEditor.Editor + { + internal bool pathFoldout = false; + internal bool advancedFoldout = false; + public override void OnInspectorGUI() + { + AssetBundle bundle = target as AssetBundle; + + using (new EditorGUI.DisabledScope(true)) + { + var leftStyle = new GUIStyle(GUI.skin.GetStyle("Label")); + leftStyle.alignment = TextAnchor.UpperLeft; + GUILayout.Label(new GUIContent("Name: " + bundle.name), leftStyle); + + var assetNames = bundle.GetAllAssetNames(); + pathFoldout = EditorGUILayout.Foldout(pathFoldout, "Source Asset Paths"); + if (pathFoldout) + { + EditorGUI.indentLevel++; + foreach (var asset in assetNames) + EditorGUILayout.LabelField(asset); + EditorGUI.indentLevel--; + } + + advancedFoldout = EditorGUILayout.Foldout(advancedFoldout, "Advanced Data"); + } + + if (advancedFoldout) + { + EditorGUI.indentLevel++; + base.OnInspectorGUI(); + EditorGUI.indentLevel--; + } + } + } + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Editor/AssetBundleReporter/AssetBundleInspector.cs.meta b/Assets/YooAsset/Editor/AssetBundleReporter/AssetBundleInspector.cs.meta new file mode 100644 index 0000000..d1a870d --- /dev/null +++ b/Assets/YooAsset/Editor/AssetBundleReporter/AssetBundleInspector.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b8016a4c13444bf45830d714ab2aa430 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Editor/AssetBundleReporter/AssetBundleRecorder.cs b/Assets/YooAsset/Editor/AssetBundleReporter/AssetBundleRecorder.cs new file mode 100644 index 0000000..1ce2b3f --- /dev/null +++ b/Assets/YooAsset/Editor/AssetBundleReporter/AssetBundleRecorder.cs @@ -0,0 +1,65 @@ +using System.IO; +using System.Collections.Generic; +using UnityEditor; +using UnityEngine; + +namespace YooAsset.Editor +{ + public static class AssetBundleRecorder + { + private static readonly Dictionary _loadedAssetBundles = new Dictionary(1000); + + /// + /// 获取AssetBundle对象,如果没有被缓存就重新加载。 + /// + public static AssetBundle GetAssetBundle(string filePath) + { + // 如果文件不存在 + if (File.Exists(filePath) == false) + { + Debug.LogWarning($"Not found asset bundle file : {filePath}"); + return null; + } + + // 验证文件有效性(可能文件被加密) + byte[] fileData = File.ReadAllBytes(filePath); + if (EditorTools.CheckBundleFileValid(fileData) == false) + { + Debug.LogWarning($"The asset bundle file is invalid and may be encrypted : {filePath}"); + return null; + } + + if (_loadedAssetBundles.TryGetValue(filePath, out AssetBundle bundle)) + { + return bundle; + } + else + { + AssetBundle newBundle = AssetBundle.LoadFromFile(filePath); + if(newBundle != null) + { + string[] assetNames = newBundle.GetAllAssetNames(); + foreach (string name in assetNames) + { + newBundle.LoadAsset(name); + } + _loadedAssetBundles.Add(filePath, newBundle); + } + return newBundle; + } + } + + /// + /// 卸载所有已经加载的AssetBundle文件 + /// + public static void UnloadAll() + { + foreach(var valuePair in _loadedAssetBundles) + { + if (valuePair.Value != null) + valuePair.Value.Unload(true); + } + _loadedAssetBundles.Clear(); + } + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Editor/AssetBundleReporter/AssetBundleRecorder.cs.meta b/Assets/YooAsset/Editor/AssetBundleReporter/AssetBundleRecorder.cs.meta new file mode 100644 index 0000000..92fac08 --- /dev/null +++ b/Assets/YooAsset/Editor/AssetBundleReporter/AssetBundleRecorder.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9b2b5e436ee882d41bf53082bf7b23a0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Editor/AssetBundleReporter/AssetBundleReporterWindow.cs b/Assets/YooAsset/Editor/AssetBundleReporter/AssetBundleReporterWindow.cs index c08da5b..149aa00 100644 --- a/Assets/YooAsset/Editor/AssetBundleReporter/AssetBundleReporterWindow.cs +++ b/Assets/YooAsset/Editor/AssetBundleReporter/AssetBundleReporterWindow.cs @@ -42,8 +42,9 @@ namespace YooAsset.Editor private BundleListReporterViewer _bundleListViewer; private EViewMode _viewMode; - private string _searchKeyWord; private BuildReport _buildReport; + private string _reportFilePath; + private string _searchKeyWord; public void CreateGUI() @@ -92,6 +93,10 @@ namespace YooAsset.Editor _viewModeMenu.text = EViewMode.Summary.ToString(); _summaryViewer.AttachParent(root); } + public void OnDestroy() + { + AssetBundleRecorder.UnloadAll(); + } private void ImportBtn_onClick() { @@ -99,19 +104,20 @@ namespace YooAsset.Editor if (string.IsNullOrEmpty(selectFilePath)) return; - string jsonData = FileUtility.ReadFile(selectFilePath); + _reportFilePath = selectFilePath; + string jsonData = FileUtility.ReadFile(_reportFilePath); _buildReport = BuildReport.Deserialize(jsonData); _assetListViewer.FillViewData(_buildReport, _searchKeyWord); - _bundleListViewer.FillViewData(_buildReport, _searchKeyWord); + _bundleListViewer.FillViewData(_buildReport, _reportFilePath, _searchKeyWord); _summaryViewer.FillViewData(_buildReport); } private void OnSearchKeyWordChange(ChangeEvent e) { _searchKeyWord = e.newValue; - if(_buildReport != null) + if (_buildReport != null) { _assetListViewer.FillViewData(_buildReport, _searchKeyWord); - _bundleListViewer.FillViewData(_buildReport, _searchKeyWord); + _bundleListViewer.FillViewData(_buildReport, _reportFilePath, _searchKeyWord); } } private void ViewModeMenuAction0(DropdownMenuAction action) diff --git a/Assets/YooAsset/Editor/AssetBundleReporter/VisualViewers/AssetListReporterViewer.cs b/Assets/YooAsset/Editor/AssetBundleReporter/VisualViewers/AssetListReporterViewer.cs index 9bda204..f189ecf 100644 --- a/Assets/YooAsset/Editor/AssetBundleReporter/VisualViewers/AssetListReporterViewer.cs +++ b/Assets/YooAsset/Editor/AssetBundleReporter/VisualViewers/AssetListReporterViewer.cs @@ -322,7 +322,7 @@ namespace YooAsset.Editor // Size var label2 = element.Q