Update AssetBundleReporter

pull/4/head
hevinci 2022-03-18 11:24:55 +08:00
parent 233e477bc8
commit 8ee06ccf76
14 changed files with 100 additions and 120 deletions

View File

@ -1,7 +1,4 @@
#if UNITY_2019_4_OR_NEWER
using System.IO;
using System.Linq;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEditor.UIElements;
@ -9,14 +6,14 @@ using UnityEngine.UIElements;
namespace YooAsset.Editor
{
public class AssetBundleBrowserWindow : EditorWindow
public class AssetBundleReporterWindow : EditorWindow
{
[MenuItem("YooAsset/AssetBundle Browser", false, 103)]
[MenuItem("YooAsset/AssetBundle Reporter", false, 103)]
public static void ShowExample()
{
AssetBundleBrowserWindow wnd = GetWindow<AssetBundleBrowserWindow>();
wnd.titleContent = new GUIContent("资源包浏览工具");
wnd.minSize = new Vector2(800, 600);
AssetBundleReporterWindow window = GetWindow<AssetBundleReporterWindow>();
window.titleContent = new GUIContent("资源包报告工具");
window.minSize = new Vector2(800, 600);
}
/// <summary>
@ -36,12 +33,12 @@ namespace YooAsset.Editor
}
private ToolbarMenu _showModeMenu;
private AssetListBrowserViewer _assetListViewer;
private BundleListBrowserViewer _bundleListViewer;
private AssetListReporterViewer _assetListViewer;
private BundleListReporterViewer _bundleListViewer;
private EShowMode _showMode;
private string _searchKeyWord;
private PatchManifest _manifest;
private BuildReport _buildReport;
public void CreateGUI()
@ -50,11 +47,11 @@ namespace YooAsset.Editor
// 加载布局文件
string rootPath = EditorTools.GetYooAssetPath();
string uxml = $"{rootPath}/Editor/AssetBundleBrowser/AssetBundleBrowser.uxml";
string uxml = $"{rootPath}/Editor/AssetBundleReporter/AssetBundleReporter.uxml";
var visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
if (visualAsset == null)
{
Debug.LogError($"Not found AssetBundleBrowser.uxml : {uxml}");
Debug.LogError($"Not found AssetBundleReporter.uxml : {uxml}");
return;
}
visualAsset.CloneTree(root);
@ -73,11 +70,11 @@ namespace YooAsset.Editor
searchField.RegisterValueChangedCallback(OnSearchKeyWordChange);
// 加载页面
_assetListViewer = new AssetListBrowserViewer();
_assetListViewer = new AssetListReporterViewer();
_assetListViewer.InitViewer();
// 加载页面
_bundleListViewer = new BundleListBrowserViewer();
_bundleListViewer = new BundleListReporterViewer();
_bundleListViewer.InitViewer();
// 初始页面
@ -88,22 +85,22 @@ namespace YooAsset.Editor
private void ImportBtn_onClick()
{
string selectFilePath = EditorUtility.OpenFilePanel("导入补丁清单", EditorTools.GetProjectPath(), "bytes");
string selectFilePath = EditorUtility.OpenFilePanel("导入报告", EditorTools.GetProjectPath(), "json");
if (string.IsNullOrEmpty(selectFilePath))
return;
string jsonData = FileUtility.ReadFile(selectFilePath);
_manifest = PatchManifest.Deserialize(jsonData);
_assetListViewer.FillViewData(_manifest, _searchKeyWord);
_bundleListViewer.FillViewData(_manifest, _searchKeyWord);
_buildReport = BuildReport.Deserialize(jsonData);
_assetListViewer.FillViewData(_buildReport, _searchKeyWord);
_bundleListViewer.FillViewData(_buildReport, _searchKeyWord);
}
private void OnSearchKeyWordChange(ChangeEvent<string> e)
{
_searchKeyWord = e.newValue;
if(_manifest != null)
if(_buildReport != null)
{
_assetListViewer.FillViewData(_manifest, _searchKeyWord);
_bundleListViewer.FillViewData(_manifest, _searchKeyWord);
_assetListViewer.FillViewData(_buildReport, _searchKeyWord);
_bundleListViewer.FillViewData(_buildReport, _searchKeyWord);
}
}
private void ShowModeMenuAction1(DropdownMenuAction action)

View File

@ -9,7 +9,7 @@ using UnityEngine.UIElements;
namespace YooAsset.Editor
{
internal class AssetListBrowserViewer
internal class AssetListReporterViewer
{
private VisualTreeAsset _visualAsset;
private TemplateContainer _root;
@ -22,7 +22,7 @@ namespace YooAsset.Editor
private ToolbarButton _bottomBar3;
private ListView _assetListView;
private ListView _dependListView;
private PatchManifest _manifest;
private BuildReport _buildReport;
/// <summary>
/// 初始化页面
@ -31,11 +31,11 @@ namespace YooAsset.Editor
{
// 加载布局文件
string rootPath = EditorTools.GetYooAssetPath();
string uxml = $"{rootPath}/Editor/AssetBundleBrowser/VisualViewers/AssetListBrowserViewer.uxml";
string uxml = $"{rootPath}/Editor/AssetBundleReporter/VisualViewers/AssetListReporterViewer.uxml";
_visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
if (_visualAsset == null)
{
Debug.LogError($"Not found {nameof(AssetListBrowserViewer)}.uxml : {uxml}");
Debug.LogError($"Not found {nameof(AssetListReporterViewer)}.uxml : {uxml}");
return;
}
_root = _visualAsset.CloneTree();
@ -73,24 +73,24 @@ namespace YooAsset.Editor
/// <summary>
/// 填充页面数据
/// </summary>
public void FillViewData(PatchManifest manifest, string searchKeyWord)
public void FillViewData(BuildReport buildReport, string searchKeyWord)
{
_manifest = manifest;
_buildReport = buildReport;
_assetListView.Clear();
_assetListView.itemsSource = FilterViewItems(manifest, searchKeyWord);
_assetListView.itemsSource = FilterViewItems(buildReport, searchKeyWord);
_topBar1.text = $"Asset Path ({_assetListView.itemsSource.Count})";
}
private List<PatchAsset> FilterViewItems(PatchManifest manifest, string searchKeyWord)
private List<ReportAssetInfo> FilterViewItems(BuildReport buildReport, string searchKeyWord)
{
List<PatchAsset> result = new List<PatchAsset>(manifest.AssetList.Count);
foreach (var patchAsset in manifest.AssetList)
List<ReportAssetInfo> result = new List<ReportAssetInfo>(buildReport.AssetInfos.Count);
foreach (var assetInfo in buildReport.AssetInfos)
{
if(string.IsNullOrEmpty(searchKeyWord) == false)
{
if (patchAsset.AssetPath.Contains(searchKeyWord) == false)
if (assetInfo.AssetPath.Contains(searchKeyWord) == false)
continue;
}
result.Add(patchAsset);
result.Add(assetInfo);
}
return result;
}
@ -152,28 +152,28 @@ namespace YooAsset.Editor
}
private void BindAssetListViewItem(VisualElement element, int index)
{
var sourceData = _assetListView.itemsSource as List<PatchAsset>;
var patchAsset = sourceData[index];
var patchBundle = _manifest.BundleList[patchAsset.BundleID];
var sourceData = _assetListView.itemsSource as List<ReportAssetInfo>;
var assetInfo = sourceData[index];
var bundleInfo = _buildReport.GetBundleInfo(assetInfo.MainBundle);
// Asset Path
var label1 = element.Q<Label>("Label1");
label1.text = patchAsset.AssetPath;
label1.text = assetInfo.AssetPath;
// Size
var label2 = element.Q<Label>("Label2");
label2.text = GetAssetFileSize(patchAsset.AssetPath);
label2.text = GetAssetFileSize(assetInfo.AssetPath);
// Main Bundle
var label3 = element.Q<Label>("Label3");
label3.text = patchBundle.BundleName;
label3.text = bundleInfo.BundleName;
}
private void AssetListView_onSelectionChange(IEnumerable<object> objs)
{
foreach (var item in objs)
{
PatchAsset patchAsset = item as PatchAsset;
FillDependListView(patchAsset);
ReportAssetInfo assetInfo = item as ReportAssetInfo;
FillDependListView(assetInfo);
}
}
private void TopBar1_clicked()
@ -187,6 +187,24 @@ namespace YooAsset.Editor
}
// 依赖列表相关
private void FillDependListView(ReportAssetInfo assetInfo)
{
List<ReportBundleInfo> bundles = new List<ReportBundleInfo>();
var mainBundle = _buildReport.GetBundleInfo(assetInfo.MainBundle);
bundles.Add(mainBundle);
foreach(string dependBundleName in assetInfo.DependBundles)
{
var dependBundle = _buildReport.GetBundleInfo(dependBundleName);
bundles.Add(dependBundle);
}
_dependListView.Clear();
#if UNITY_2020_1_OR_NEWER
_dependListView.ClearSelection();
#endif
_dependListView.itemsSource = bundles;
_bottomBar1.text = $"Depend Bundles ({bundles.Count})";
}
private VisualElement MakeDependListViewItem()
{
VisualElement element = new VisualElement();
@ -226,39 +244,20 @@ namespace YooAsset.Editor
}
private void BindDependListViewItem(VisualElement element, int index)
{
List<PatchBundle> bundles = _dependListView.itemsSource as List<PatchBundle>;
PatchBundle patchBundle = bundles[index];
List<ReportBundleInfo> bundles = _dependListView.itemsSource as List<ReportBundleInfo>;
ReportBundleInfo bundleInfo = bundles[index];
// Bundle Name
var label1 = element.Q<Label>("Label1");
label1.text = patchBundle.BundleName;
label1.text = bundleInfo.BundleName;
// Size
var label2 = element.Q<Label>("Label2");
label2.text = (patchBundle.SizeBytes / 1024f).ToString("f1") + " KB";
label2.text = (bundleInfo.SizeBytes / 1024f).ToString("f1") + " KB";
// Hash
var label3 = element.Q<Label>("Label3");
label3.text = patchBundle.Hash;
}
private void FillDependListView(PatchAsset patchAsset)
{
List<PatchBundle> bundles = new List<PatchBundle>();
var mainBundle = _manifest.BundleList[patchAsset.BundleID];
bundles.Add(mainBundle);
for (int i = 0; i < patchAsset.DependIDs.Length; i++)
{
int bundleID = patchAsset.DependIDs[i];
var dependBundle = _manifest.BundleList[bundleID];
bundles.Add(dependBundle);
}
_dependListView.Clear();
#if UNITY_2020_1_OR_NEWER
_dependListView.ClearSelection();
#endif
_dependListView.itemsSource = bundles;
_bottomBar1.text = $"Depend Bundles ({bundles.Count})";
label3.text = bundleInfo.Hash;
}
private string GetAssetFileSize(string assetPath)

View File

@ -9,7 +9,7 @@ using UnityEngine.UIElements;
namespace YooAsset.Editor
{
internal class BundleListBrowserViewer
internal class BundleListReporterViewer
{
private VisualTreeAsset _visualAsset;
private TemplateContainer _root;
@ -24,7 +24,7 @@ namespace YooAsset.Editor
private ToolbarButton _bottomBar3;
private ListView _bundleListView;
private ListView _includeListView;
private PatchManifest _manifest;
private BuildReport _buildReport;
/// <summary>
/// 初始化页面
@ -33,11 +33,11 @@ namespace YooAsset.Editor
{
// 加载布局文件
string rootPath = EditorTools.GetYooAssetPath();
string uxml = $"{rootPath}/Editor/AssetBundleBrowser/VisualViewers/BundleListBrowserViewer.uxml";
string uxml = $"{rootPath}/Editor/AssetBundleReporter/VisualViewers/BundleListReporterViewer.uxml";
_visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
if (_visualAsset == null)
{
Debug.LogError($"Not found {nameof(BundleListBrowserViewer)}.uxml : {uxml}");
Debug.LogError($"Not found {nameof(BundleListReporterViewer)}.uxml : {uxml}");
return;
}
_root = _visualAsset.CloneTree();
@ -74,24 +74,24 @@ namespace YooAsset.Editor
/// <summary>
/// 填充页面数据
/// </summary>
public void FillViewData(PatchManifest manifest, string searchKeyWord)
public void FillViewData(BuildReport buildReport, string searchKeyWord)
{
_manifest = manifest;
_buildReport = buildReport;
_bundleListView.Clear();
_bundleListView.itemsSource = FilterViewItems(manifest, searchKeyWord);
_bundleListView.itemsSource = FilterViewItems(buildReport, searchKeyWord);
_topBar1.text = $"Bundle Name ({_bundleListView.itemsSource.Count})";
}
private List<PatchBundle> FilterViewItems(PatchManifest manifest, string searchKeyWord)
private List<ReportBundleInfo> FilterViewItems(BuildReport buildReport, string searchKeyWord)
{
List<PatchBundle> result = new List<PatchBundle>(manifest.BundleList.Count);
foreach (var patchBundle in manifest.BundleList)
List<ReportBundleInfo> result = new List<ReportBundleInfo>(buildReport.BundleInfos.Count);
foreach (var bundleInfo in buildReport.BundleInfos)
{
if (string.IsNullOrEmpty(searchKeyWord) == false)
{
if (patchBundle.BundleName.Contains(searchKeyWord) == false)
if (bundleInfo.BundleName.Contains(searchKeyWord) == false)
continue;
}
result.Add(patchBundle);
result.Add(bundleInfo);
}
return result;
}
@ -173,39 +173,55 @@ namespace YooAsset.Editor
}
private void BindBundleListViewItem(VisualElement element, int index)
{
var sourceData = _bundleListView.itemsSource as List<PatchBundle>;
var patchBundle = sourceData[index];
var sourceData = _bundleListView.itemsSource as List<ReportBundleInfo>;
var bundleInfo = sourceData[index];
// Bundle Name
var label1 = element.Q<Label>("Label1");
label1.text = patchBundle.BundleName;
label1.text = bundleInfo.BundleName;
// Size
var label2 = element.Q<Label>("Label2");
label2.text = (patchBundle.SizeBytes / 1024f).ToString("f1") + " KB";
label2.text = (bundleInfo.SizeBytes / 1024f).ToString("f1") + " KB";
// Hash
var label3 = element.Q<Label>("Label3");
label3.text = patchBundle.Hash;
label3.text = bundleInfo.Hash;
// Version
var label4 = element.Q<Label>("Label4");
label4.text = patchBundle.Version.ToString();
label4.text = bundleInfo.Version.ToString();
// Tags
var label5 = element.Q<Label>("Label5");
label5.text = GetTagsString(patchBundle.Tags);
label5.text = GetTagsString(bundleInfo.Tags);
}
private void BundleListView_onSelectionChange(IEnumerable<object> objs)
{
foreach (var item in objs)
{
PatchBundle patchBundle = item as PatchBundle;
FillContainsListView(patchBundle);
ReportBundleInfo bundleInfo = item as ReportBundleInfo;
FillContainsListView(bundleInfo);
}
}
// 依赖列表相关
private void FillContainsListView(ReportBundleInfo bundleInfo)
{
List<string> containsList = new List<string>();
foreach (var assetInfo in _buildReport.AssetInfos)
{
if (assetInfo.MainBundle == bundleInfo.BundleName)
containsList.Add(assetInfo.AssetPath);
}
_includeListView.Clear();
#if UNITY_2020_1_OR_NEWER
_includeListView.ClearSelection();
#endif
_includeListView.itemsSource = containsList;
_bottomBar1.text = $"Include Assets ({containsList.Count})";
}
private VisualElement MakeContainsListViewItem()
{
VisualElement element = new VisualElement();
@ -260,38 +276,6 @@ namespace YooAsset.Editor
var label3 = element.Q<Label>("Label3");
label3.text = AssetDatabase.AssetPathToGUID(assetPath);
}
private void FillContainsListView(PatchBundle patchBundle)
{
List<string> containsList = new List<string>();
int bundleID = -1;
for (int i = 0; i < _manifest.BundleList.Count; i++)
{
if (_manifest.BundleList[i] == patchBundle)
{
bundleID = i;
break;
}
}
if (bundleID == -1)
{
Debug.LogError($"Not found bundle in PatchManifest : {patchBundle.BundleName}");
return;
}
foreach (var patchAsset in _manifest.AssetList)
{
if (patchAsset.BundleID == bundleID)
containsList.Add(patchAsset.AssetPath);
}
_includeListView.Clear();
#if UNITY_2020_1_OR_NEWER
_includeListView.ClearSelection();
#endif
_includeListView.itemsSource = containsList;
_bottomBar1.text = $"Include Assets ({containsList.Count})";
}
private string GetAssetFileSize(string assetPath)
{