mirror of https://github.com/tuyoogame/YooAsset
parent
bd87e982ef
commit
c22c87e16b
|
@ -8,6 +8,21 @@ namespace YooAsset.Editor
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class ReportBundleInfo
|
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;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源包名称
|
/// 资源包名称
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -38,6 +53,26 @@ namespace YooAsset.Editor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Flags;
|
public int Flags;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取标志位的解析数据
|
||||||
|
/// </summary>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取资源分类标签的字符串
|
||||||
|
/// </summary>
|
||||||
public string GetTagsString()
|
public string GetTagsString()
|
||||||
{
|
{
|
||||||
if (Tags != null)
|
if (Tags != null)
|
||||||
|
@ -45,5 +80,16 @@ namespace YooAsset.Editor
|
||||||
else
|
else
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否为原生文件
|
||||||
|
/// </summary>
|
||||||
|
public bool IsRawFile()
|
||||||
|
{
|
||||||
|
if (System.IO.Path.GetExtension(BundleName) == $".{YooAssetSettingsData.Setting.RawFileVariant}")
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b8016a4c13444bf45830d714ab2aa430
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -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<string, AssetBundle> _loadedAssetBundles = new Dictionary<string, AssetBundle>(1000);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取AssetBundle对象,如果没有被缓存就重新加载。
|
||||||
|
/// </summary>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 卸载所有已经加载的AssetBundle文件
|
||||||
|
/// </summary>
|
||||||
|
public static void UnloadAll()
|
||||||
|
{
|
||||||
|
foreach(var valuePair in _loadedAssetBundles)
|
||||||
|
{
|
||||||
|
if (valuePair.Value != null)
|
||||||
|
valuePair.Value.Unload(true);
|
||||||
|
}
|
||||||
|
_loadedAssetBundles.Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 9b2b5e436ee882d41bf53082bf7b23a0
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -42,8 +42,9 @@ namespace YooAsset.Editor
|
||||||
private BundleListReporterViewer _bundleListViewer;
|
private BundleListReporterViewer _bundleListViewer;
|
||||||
|
|
||||||
private EViewMode _viewMode;
|
private EViewMode _viewMode;
|
||||||
private string _searchKeyWord;
|
|
||||||
private BuildReport _buildReport;
|
private BuildReport _buildReport;
|
||||||
|
private string _reportFilePath;
|
||||||
|
private string _searchKeyWord;
|
||||||
|
|
||||||
|
|
||||||
public void CreateGUI()
|
public void CreateGUI()
|
||||||
|
@ -92,6 +93,10 @@ namespace YooAsset.Editor
|
||||||
_viewModeMenu.text = EViewMode.Summary.ToString();
|
_viewModeMenu.text = EViewMode.Summary.ToString();
|
||||||
_summaryViewer.AttachParent(root);
|
_summaryViewer.AttachParent(root);
|
||||||
}
|
}
|
||||||
|
public void OnDestroy()
|
||||||
|
{
|
||||||
|
AssetBundleRecorder.UnloadAll();
|
||||||
|
}
|
||||||
|
|
||||||
private void ImportBtn_onClick()
|
private void ImportBtn_onClick()
|
||||||
{
|
{
|
||||||
|
@ -99,10 +104,11 @@ namespace YooAsset.Editor
|
||||||
if (string.IsNullOrEmpty(selectFilePath))
|
if (string.IsNullOrEmpty(selectFilePath))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
string jsonData = FileUtility.ReadFile(selectFilePath);
|
_reportFilePath = selectFilePath;
|
||||||
|
string jsonData = FileUtility.ReadFile(_reportFilePath);
|
||||||
_buildReport = BuildReport.Deserialize(jsonData);
|
_buildReport = BuildReport.Deserialize(jsonData);
|
||||||
_assetListViewer.FillViewData(_buildReport, _searchKeyWord);
|
_assetListViewer.FillViewData(_buildReport, _searchKeyWord);
|
||||||
_bundleListViewer.FillViewData(_buildReport, _searchKeyWord);
|
_bundleListViewer.FillViewData(_buildReport, _reportFilePath, _searchKeyWord);
|
||||||
_summaryViewer.FillViewData(_buildReport);
|
_summaryViewer.FillViewData(_buildReport);
|
||||||
}
|
}
|
||||||
private void OnSearchKeyWordChange(ChangeEvent<string> e)
|
private void OnSearchKeyWordChange(ChangeEvent<string> e)
|
||||||
|
@ -111,7 +117,7 @@ namespace YooAsset.Editor
|
||||||
if (_buildReport != null)
|
if (_buildReport != null)
|
||||||
{
|
{
|
||||||
_assetListViewer.FillViewData(_buildReport, _searchKeyWord);
|
_assetListViewer.FillViewData(_buildReport, _searchKeyWord);
|
||||||
_bundleListViewer.FillViewData(_buildReport, _searchKeyWord);
|
_bundleListViewer.FillViewData(_buildReport, _reportFilePath, _searchKeyWord);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void ViewModeMenuAction0(DropdownMenuAction action)
|
private void ViewModeMenuAction0(DropdownMenuAction action)
|
||||||
|
|
|
@ -322,7 +322,7 @@ namespace YooAsset.Editor
|
||||||
|
|
||||||
// Size
|
// Size
|
||||||
var label2 = element.Q<Label>("Label2");
|
var label2 = element.Q<Label>("Label2");
|
||||||
label2.text = (bundleInfo.SizeBytes / 1024f).ToString("f1") + " KB";
|
label2.text = EditorUtility.FormatBytes(bundleInfo.SizeBytes);
|
||||||
|
|
||||||
// Hash
|
// Hash
|
||||||
var label3 = element.Q<Label>("Label3");
|
var label3 = element.Q<Label>("Label3");
|
||||||
|
|
|
@ -31,11 +31,11 @@ namespace YooAsset.Editor
|
||||||
private ListView _includeListView;
|
private ListView _includeListView;
|
||||||
|
|
||||||
private BuildReport _buildReport;
|
private BuildReport _buildReport;
|
||||||
|
private string _reportFilePath;
|
||||||
private string _searchKeyWord;
|
private string _searchKeyWord;
|
||||||
private ESortMode _sortMode = ESortMode.BundleName;
|
private ESortMode _sortMode = ESortMode.BundleName;
|
||||||
private bool _descendingSort = false;
|
private bool _descendingSort = false;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 初始化页面
|
/// 初始化页面
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -93,9 +93,10 @@ namespace YooAsset.Editor
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 填充页面数据
|
/// 填充页面数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void FillViewData(BuildReport buildReport, string searchKeyWord)
|
public void FillViewData( BuildReport buildReport, string reprotFilePath, string searchKeyWord)
|
||||||
{
|
{
|
||||||
_buildReport = buildReport;
|
_buildReport = buildReport;
|
||||||
|
_reportFilePath = reprotFilePath;
|
||||||
_searchKeyWord = searchKeyWord;
|
_searchKeyWord = searchKeyWord;
|
||||||
RefreshView();
|
RefreshView();
|
||||||
}
|
}
|
||||||
|
@ -260,7 +261,7 @@ namespace YooAsset.Editor
|
||||||
|
|
||||||
// Size
|
// Size
|
||||||
var label2 = element.Q<Label>("Label2");
|
var label2 = element.Q<Label>("Label2");
|
||||||
label2.text = (bundleInfo.SizeBytes / 1024f).ToString("f1") + " KB";
|
label2.text = EditorUtility.FormatBytes(bundleInfo.SizeBytes);
|
||||||
|
|
||||||
// Hash
|
// Hash
|
||||||
var label3 = element.Q<Label>("Label3");
|
var label3 = element.Q<Label>("Label3");
|
||||||
|
@ -276,8 +277,22 @@ namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
ReportBundleInfo bundleInfo = item as ReportBundleInfo;
|
ReportBundleInfo bundleInfo = item as ReportBundleInfo;
|
||||||
FillIncludeListView(bundleInfo);
|
FillIncludeListView(bundleInfo);
|
||||||
|
ShowAssetBundleInspector(bundleInfo);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private void ShowAssetBundleInspector(ReportBundleInfo bundleInfo)
|
||||||
|
{
|
||||||
|
if (bundleInfo.IsRawFile())
|
||||||
|
return;
|
||||||
|
|
||||||
|
string rootDirectory = Path.GetDirectoryName(_reportFilePath);
|
||||||
|
string filePath = $"{rootDirectory}/{bundleInfo.Hash}";
|
||||||
|
if (File.Exists(filePath))
|
||||||
|
Selection.activeObject = AssetBundleRecorder.GetAssetBundle(filePath);
|
||||||
|
else
|
||||||
|
Selection.activeObject = null;
|
||||||
|
}
|
||||||
private void TopBar1_clicked()
|
private void TopBar1_clicked()
|
||||||
{
|
{
|
||||||
if (_sortMode != ESortMode.BundleName)
|
if (_sortMode != ESortMode.BundleName)
|
||||||
|
|
Loading…
Reference in New Issue