Fixed editor window display exception at unity2021

修复工具界面显示异常在Unity2021版本下。
pull/4/head
hevinci 2022-04-24 13:11:19 +08:00
parent a6e94acefb
commit cbf142dbf8
14 changed files with 90 additions and 47 deletions

View File

@ -58,7 +58,9 @@ namespace YooAsset.Editor
{
_debugReport = debugReport;
_assetListView.Clear();
_assetListView.ClearSelection();
_assetListView.itemsSource = FilterViewItems(debugReport, searchKeyWord);
_assetListView.Rebuild();
}
private List<DebugProviderInfo> FilterViewItems(DebugReport debugReport, string searchKeyWord)
{
@ -250,6 +252,7 @@ namespace YooAsset.Editor
_dependListView.Clear();
_dependListView.ClearSelection();
_dependListView.itemsSource = providerInfo.BundleInfos;
_dependListView.Rebuild();
}
}
}

View File

@ -7,7 +7,7 @@
<uie:ToolbarButton text="Ref Count" display-tooltip-when-elided="true" name="TopBar4" style="width: 100px; -unity-text-align: middle-left; flex-grow: 0;" />
<uie:ToolbarButton text="Status" display-tooltip-when-elided="true" name="TopBar5" style="width: 120px; -unity-text-align: middle-left;" />
</uie:Toolbar>
<ui:ListView focusable="true" name="TopListView" item-height="18" style="flex-grow: 1;" />
<ui:ListView focusable="true" name="TopListView" item-height="18" virtualization-method="DynamicHeight" style="flex-grow: 1;" />
</ui:VisualElement>
<ui:VisualElement name="BottomGroup" style="height: 200px; border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-width: 1px; border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-top-color: rgb(0, 0, 0); border-bottom-color: rgb(0, 0, 0); margin-left: 0; margin-right: 0; margin-top: 1px; margin-bottom: 1px; display: flex;">
<uie:Toolbar name="BottomBar" style="height: 25px; margin-left: 1px; margin-right: 1px;">
@ -15,6 +15,6 @@
<uie:ToolbarButton text="Ref Count" display-tooltip-when-elided="true" name="BottomBar3" style="width: 100px; -unity-text-align: middle-left;" />
<uie:ToolbarButton text="Status" display-tooltip-when-elided="true" name="BottomBar4" style="width: 120px; -unity-text-align: middle-left;" />
</uie:Toolbar>
<ui:ListView focusable="true" name="BottomListView" item-height="18" style="flex-grow: 1;" />
<ui:ListView focusable="true" name="BottomListView" item-height="18" virtualization-method="DynamicHeight" style="flex-grow: 1;" />
</ui:VisualElement>
</ui:UXML>

View File

@ -58,7 +58,9 @@ namespace YooAsset.Editor
{
_debugReport = debugReport;
_bundleListView.Clear();
_bundleListView.ClearSelection();
_bundleListView.itemsSource = FilterViewItems(debugReport, searchKeyWord);
_bundleListView.Rebuild();
}
private List<DebugBundleInfo> FilterViewItems(DebugReport debugReport, string searchKeyWord)
{
@ -251,9 +253,6 @@ namespace YooAsset.Editor
}
private void FillUsingListView(string bundleName)
{
_usingListView.Clear();
_usingListView.ClearSelection();
List<DebugProviderInfo> source = new List<DebugProviderInfo>();
foreach (var providerInfo in _debugReport.ProviderInfos)
{
@ -266,7 +265,11 @@ namespace YooAsset.Editor
}
}
}
_usingListView.Clear();
_usingListView.ClearSelection();
_usingListView.itemsSource = source;
_usingListView.Rebuild();
}
}
}

View File

@ -5,7 +5,7 @@
<uie:ToolbarButton text="Ref Count" display-tooltip-when-elided="true" name="TopBar3" style="width: 100px; -unity-text-align: middle-left;" />
<uie:ToolbarButton text="Status" display-tooltip-when-elided="true" name="TopBar4" style="width: 120px; -unity-text-align: middle-left;" />
</uie:Toolbar>
<ui:ListView focusable="true" name="TopListView" item-height="18" style="flex-grow: 1;" />
<ui:ListView focusable="true" name="TopListView" item-height="18" virtualization-method="DynamicHeight" style="flex-grow: 1;" />
</ui:VisualElement>
<ui:VisualElement name="BottomGroup" style="height: 200px; border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-width: 1px; border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-top-color: rgb(0, 0, 0); border-bottom-color: rgb(0, 0, 0); margin-left: 0; margin-right: 0; margin-top: 1px; margin-bottom: 1px; display: flex;">
<uie:Toolbar name="BottomBar" style="height: 25px; margin-left: 1px; margin-right: 1px;">
@ -15,6 +15,6 @@
<uie:ToolbarButton text="Ref Count" display-tooltip-when-elided="true" name="BottomBar4" style="width: 100px; -unity-text-align: middle-left;" />
<uie:ToolbarButton text="Status" display-tooltip-when-elided="true" name="BottomBar5" style="width: 120px; -unity-text-align: middle-left;" />
</uie:Toolbar>
<ui:ListView focusable="true" name="BottomListView" item-height="18" style="flex-grow: 1;" />
<ui:ListView focusable="true" name="BottomListView" item-height="18" virtualization-method="DynamicHeight" style="flex-grow: 1;" />
</ui:VisualElement>
</ui:UXML>

View File

@ -34,6 +34,9 @@ namespace YooAsset.Editor
/// </summary>
public string AssetTags = string.Empty;
[NonSerialized]
public object UserData;
/// <summary>
/// 检测配置错误

View File

@ -22,7 +22,7 @@ namespace YooAsset.Editor
private List<string> _packRuleList;
private List<string> _filterRuleList;
private ListView _grouperListView;
private ListView _collectorListView;
private ScrollView _collectorScrollView;
private Toggle _autoCollectShaderToogle;
private TextField _shaderBundleNameTxt;
private TextField _grouperNameTxt;
@ -126,22 +126,15 @@ namespace YooAsset.Editor
});
// 收集列表相关
_collectorListView = root.Q<ListView>("CollectorListView");
_collectorListView.makeItem = MakeCollectorListViewItem;
_collectorListView.bindItem = BindCollectorListViewItem;
#if UNITY_2020_1_OR_NEWER
_collectorListView.onSelectionChange += CollectorListView_onSelectionChange;
#else
_collectorListView.onSelectionChanged += CollectorListView_onSelectionChange;
#endif
_collectorScrollView = root.Q<ScrollView>("CollectorScrollView");
_collectorScrollView.style.height = new Length(100, LengthUnit.Percent);
_collectorScrollView.viewDataKey = "scrollView";
// 收集添加删除按钮
// 收集器创建按钮
var collectorAddContainer = root.Q("CollectorAddContainer");
{
var addBtn = collectorAddContainer.Q<Button>("AddBtn");
addBtn.clicked += AddCollectorBtn_clicked;
var removeBtn = collectorAddContainer.Q<Button>("RemoveBtn");
removeBtn.clicked += RemoveCollectorBtn_clicked;
}
// 刷新窗体
@ -194,6 +187,7 @@ namespace YooAsset.Editor
_grouperListView.Clear();
_grouperListView.ClearSelection();
_grouperListView.itemsSource = AssetBundleGrouperSettingData.Setting.Groupers;
_grouperListView.Rebuild();
}
private VisualElement MakeGrouperListViewItem()
{
@ -251,13 +245,20 @@ namespace YooAsset.Editor
}
_grouperContainer.visible = true;
_collectorListView.Clear();
_collectorListView.ClearSelection();
_collectorListView.itemsSource = selectGrouper.Collectors;
_grouperNameTxt.SetValueWithoutNotify(selectGrouper.GrouperName);
_grouperDescTxt.SetValueWithoutNotify(selectGrouper.GrouperDesc);
_grouperAssetTagsTxt.SetValueWithoutNotify(selectGrouper.AssetTags);
// 填充数据
_collectorScrollView.Clear();
for (int i = 0; i < selectGrouper.Collectors.Count; i++)
{
var collector = selectGrouper.Collectors[i];
VisualElement element = MakeCollectorListViewItem();
collector.UserData = element;
BindCollectorListViewItem(element, i);
_collectorScrollView.Add(element);
}
}
private VisualElement MakeCollectorListViewItem()
{
@ -271,11 +272,15 @@ namespace YooAsset.Editor
elementBottom.style.flexDirection = FlexDirection.Row;
element.Add(elementBottom);
VisualElement elementFold = new VisualElement();
elementFold.style.flexDirection = FlexDirection.Row;
element.Add(elementFold);
// Top VisualElement
{
var objectField = new ObjectField();
objectField.name = "ObjectField1";
objectField.label = "Collect Path";
objectField.label = "Collecter";
objectField.objectType = typeof(UnityEngine.Object);
objectField.style.unityTextAlign = TextAnchor.MiddleLeft;
objectField.style.flexGrow = 1f;
@ -283,6 +288,14 @@ namespace YooAsset.Editor
var label = objectField.Q<Label>();
label.style.minWidth = 80;
}
{
var button = new Button();
button.name = "Button1";
button.text = "[ - ]";
button.style.unityTextAlign = TextAnchor.MiddleCenter;
button.style.flexGrow = 0f;
elementTop.Add(button);
}
// Bottom VisualElement
{
@ -336,6 +349,8 @@ namespace YooAsset.Editor
return;
var collector = selectGrouper.Collectors[index];
collector.UserData = element;
var collectObject = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(collector.CollectPath);
if (collectObject != null)
collectObject.name = collector.CollectPath;
@ -350,6 +365,13 @@ namespace YooAsset.Editor
AssetBundleGrouperSettingData.ModifyCollector(selectGrouper, collector);
});
// Remove Button
var removeBtn = element.Q<Button>("Button1");
removeBtn.clicked += ()=>
{
RemoveCollectorBtn_clicked(collector);
};
// Pack Rule
var popupField1 = element.Q<PopupField<string>>("PopupField1");
popupField1.index = GetPackRuleIndex(collector.PackRuleName);
@ -386,9 +408,6 @@ namespace YooAsset.Editor
AssetBundleGrouperSettingData.ModifyCollector(selectGrouper, collector);
});
}
private void CollectorListView_onSelectionChange(IEnumerable<object> objs)
{
}
private void AddCollectorBtn_clicked()
{
var selectGrouper = _grouperListView.selectedItem as AssetBundleGrouper;
@ -398,16 +417,13 @@ namespace YooAsset.Editor
AssetBundleGrouperSettingData.CreateCollector(selectGrouper, string.Empty, nameof(PackDirectory), nameof(CollectAll), false);
FillCollectorViewData();
}
private void RemoveCollectorBtn_clicked()
private void RemoveCollectorBtn_clicked(AssetBundleCollector selectCollector)
{
var selectGrouper = _grouperListView.selectedItem as AssetBundleGrouper;
if (selectGrouper == null)
return;
var selectCollector = _collectorListView.selectedItem as AssetBundleCollector;
if (selectCollector == null)
return;
AssetBundleGrouperSettingData.RemoveCollector(selectGrouper, selectCollector);
FillCollectorViewData();
}

View File

@ -6,7 +6,7 @@
</uie:Toolbar>
<ui:VisualElement name="ContentContainer" style="flex-grow: 1; flex-direction: row;">
<ui:VisualElement name="LeftContainer" style="width: 200px; flex-grow: 0; background-color: rgb(67, 67, 67); border-left-width: 5px; border-right-width: 5px; border-top-width: 5px; border-bottom-width: 5px;">
<ui:ListView focusable="true" name="GrouperListView" item-height="20" style="flex-grow: 1;" />
<ui:ListView focusable="true" name="GrouperListView" item-height="20" virtualization-method="DynamicHeight" style="flex-grow: 1;" />
<ui:VisualElement name="GrouperAddContainer" style="height: 20px; flex-direction: row; justify-content: center;">
<ui:Button text=" - " display-tooltip-when-elided="true" name="RemoveBtn" />
<ui:Button text=" + " display-tooltip-when-elided="true" name="AddBtn" />
@ -22,10 +22,9 @@
<ui:TextField picking-mode="Ignore" label="Grouper Desc" name="GrouperDesc" />
<ui:TextField picking-mode="Ignore" label="Grouper Asset Tags" name="GrouperAssetTags" />
<ui:VisualElement name="CollectorAddContainer" style="height: 20px; flex-direction: row-reverse;">
<ui:Button text=" - " display-tooltip-when-elided="true" name="RemoveBtn" />
<ui:Button text=" + " display-tooltip-when-elided="true" name="AddBtn" />
<ui:Button text="[ + ]" display-tooltip-when-elided="true" name="AddBtn" />
</ui:VisualElement>
<ui:ListView focusable="true" name="CollectorListView" item-height="50" style="flex-grow: 1;" />
<ui:ScrollView name="CollectorScrollView" style="flex-grow: 1;" />
</ui:VisualElement>
</ui:VisualElement>
</ui:VisualElement>

View File

@ -77,7 +77,9 @@ namespace YooAsset.Editor
{
_buildReport = buildReport;
_assetListView.Clear();
_assetListView.ClearSelection();
_assetListView.itemsSource = FilterViewItems(buildReport, searchKeyWord);
_assetListView.Rebuild();
_topBar1.text = $"Asset Path ({_assetListView.itemsSource.Count})";
}
private List<ReportAssetInfo> FilterViewItems(BuildReport buildReport, string searchKeyWord)
@ -201,6 +203,7 @@ namespace YooAsset.Editor
_dependListView.Clear();
_dependListView.ClearSelection();
_dependListView.itemsSource = bundles;
_dependListView.Rebuild();
_bottomBar1.text = $"Depend Bundles ({bundles.Count})";
}
private VisualElement MakeDependListViewItem()

View File

@ -5,7 +5,7 @@
<uie:ToolbarButton text="Size" display-tooltip-when-elided="true" name="TopBar2" style="width: 100px; -unity-text-align: middle-left; flex-grow: 0;" />
<uie:ToolbarButton text="Main Bundle" display-tooltip-when-elided="true" name="TopBar3" style="width: 145px; -unity-text-align: middle-left; flex-grow: 1;" />
</uie:Toolbar>
<ui:ListView focusable="true" name="TopListView" item-height="18" style="flex-grow: 1;" />
<ui:ListView focusable="true" name="TopListView" item-height="18" virtualization-method="DynamicHeight" style="flex-grow: 1;" />
</ui:VisualElement>
<ui:VisualElement name="BottomGroup" style="height: 200px; border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-width: 1px; border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-top-color: rgb(0, 0, 0); border-bottom-color: rgb(0, 0, 0); margin-left: 0; margin-right: 0; margin-top: 1px; margin-bottom: 1px; display: flex;">
<uie:Toolbar name="BottomBar" style="height: 25px; margin-left: 1px; margin-right: 1px;">
@ -13,6 +13,6 @@
<uie:ToolbarButton text="Size" display-tooltip-when-elided="true" name="BottomBar2" style="width: 100px; -unity-text-align: middle-left; flex-grow: 0;" />
<uie:ToolbarButton text="Hash" display-tooltip-when-elided="true" name="BottomBar3" style="width: 280px; -unity-text-align: middle-left;" />
</uie:Toolbar>
<ui:ListView focusable="true" name="BottomListView" item-height="18" style="flex-grow: 1;" />
<ui:ListView focusable="true" name="BottomListView" item-height="18" virtualization-method="DynamicHeight" style="flex-grow: 1;" />
</ui:VisualElement>
</ui:UXML>

View File

@ -78,7 +78,9 @@ namespace YooAsset.Editor
{
_buildReport = buildReport;
_bundleListView.Clear();
_bundleListView.ClearSelection();
_bundleListView.itemsSource = FilterViewItems(buildReport, searchKeyWord);
_bundleListView.Rebuild();
_topBar1.text = $"Bundle Name ({_bundleListView.itemsSource.Count})";
}
private List<ReportBundleInfo> FilterViewItems(BuildReport buildReport, string searchKeyWord)
@ -204,6 +206,7 @@ namespace YooAsset.Editor
_includeListView.Clear();
_includeListView.ClearSelection();
_includeListView.itemsSource = containsList;
_includeListView.Rebuild();
_bottomBar1.text = $"Include Assets ({containsList.Count})";
}
private VisualElement MakeIncludeListViewItem()

View File

@ -7,7 +7,7 @@
<uie:ToolbarButton text="Hash" display-tooltip-when-elided="true" name="TopBar3" style="width: 280px; -unity-text-align: middle-left;" />
<uie:ToolbarButton text="Tags" display-tooltip-when-elided="true" name="TopBar5" style="width: 80px; -unity-text-align: middle-left; flex-grow: 1;" />
</uie:Toolbar>
<ui:ListView focusable="true" name="TopListView" item-height="18" style="flex-grow: 1;" />
<ui:ListView focusable="true" name="TopListView" item-height="18" virtualization-method="DynamicHeight" style="flex-grow: 1;" />
</ui:VisualElement>
<ui:VisualElement name="BottomGroup" style="height: 200px; border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-width: 1px; border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-top-color: rgb(0, 0, 0); border-bottom-color: rgb(0, 0, 0); margin-left: 0; margin-right: 0; margin-top: 1px; margin-bottom: 1px; display: flex;">
<uie:Toolbar name="BottomBar" style="height: 25px; margin-left: 1px; margin-right: 1px;">
@ -15,7 +15,7 @@
<uie:ToolbarButton text="Size" display-tooltip-when-elided="true" name="BottomBar2" style="width: 100px; -unity-text-align: middle-left;" />
<uie:ToolbarButton text="GUID" display-tooltip-when-elided="true" name="BottomBar3" style="width: 280px; -unity-text-align: middle-left;" />
</uie:Toolbar>
<ui:ListView focusable="true" name="BottomListView" item-height="18" style="flex-grow: 1;" />
<ui:ListView focusable="true" name="BottomListView" item-height="18" virtualization-method="DynamicHeight" style="flex-grow: 1;" />
</ui:VisualElement>
</ui:VisualElement>
</ui:UXML>

View File

@ -60,9 +60,8 @@ namespace YooAsset.Editor
public void FillViewData(BuildReport buildReport)
{
_buildReport = buildReport;
_listView.Clear();
_items.Clear();
_items.Clear();
_items.Add(new ItemWrapper("引擎版本", buildReport.Summary.UnityVersion));
_items.Add(new ItemWrapper("构建时间", buildReport.Summary.BuildTime));
_items.Add(new ItemWrapper("构建耗时", $"{buildReport.Summary.BuildSeconds}秒"));
@ -97,7 +96,10 @@ namespace YooAsset.Editor
_items.Add(new ItemWrapper("原生资源包总数", $"{buildReport.Summary.RawBundleTotalCount}"));
_items.Add(new ItemWrapper("原生资源包总大小", ConvertSize(buildReport.Summary.RawBundleTotalSize)));
_listView.Clear();
_listView.ClearSelection();
_listView.itemsSource = _items;
_listView.Rebuild();
}
/// <summary>

View File

@ -4,6 +4,6 @@
<uie:ToolbarButton text="概览" display-tooltip-when-elided="true" name="TopBar1" style="width: 200px; -unity-text-align: middle-left; flex-grow: 0;" />
<uie:ToolbarButton text="参数" display-tooltip-when-elided="true" name="TopBar2" style="width: 150px; -unity-text-align: middle-left; flex-grow: 1;" />
</uie:Toolbar>
<ui:ListView focusable="true" name="ListView" item-height="18" style="flex-grow: 1;" />
<ui:ListView focusable="true" name="ListView" item-height="18" virtualization-method="DynamicHeight" style="flex-grow: 1;" />
</ui:VisualElement>
</ui:UXML>

View File

@ -1,6 +1,7 @@
#if UNITY_2019_4

namespace YooAsset.Editor
{
#if UNITY_2019
public static partial class UnityEngine_UIElements_ListView_Extension
{
public static void ClearSelection(this UnityEngine.UIElements.ListView o)
@ -8,5 +9,15 @@ namespace YooAsset.Editor
o.selectedIndex = -1;
}
}
#endif
#if UNITY_2019 || UNITY_2020
public static partial class UnityEngine_UIElements_ListView_Extension
{
public static void Rebuild(this UnityEngine.UIElements.ListView o)
{
o.Refresh();
}
}
#endif
}