update asset bundle collector

pull/189/head
hevinci 2023-10-07 15:03:56 +08:00
parent 6877900ac2
commit e02fe2331d
7 changed files with 72 additions and 43 deletions

View File

@ -40,11 +40,6 @@ namespace YooAsset.Editor
/// </summary>
public System.Type AssetType { private set; get; }
/// <summary>
/// 是否为着色器资源
/// </summary>
public bool IsShaderAsset { private set; get; }
/// <summary>
/// 资源的分类标签
/// </summary>
@ -66,10 +61,6 @@ namespace YooAsset.Editor
AssetGUID = UnityEditor.AssetDatabase.AssetPathToGUID(assetPath);
AssetType = UnityEditor.AssetDatabase.GetMainAssetTypeAtPath(assetPath);
if (AssetType == typeof(UnityEngine.Shader) || AssetType == typeof(UnityEngine.ShaderVariantCollection))
IsShaderAsset = true;
else
IsShaderAsset = false;
}
public BuildAssetInfo(string assetPath)
{
@ -79,10 +70,6 @@ namespace YooAsset.Editor
AssetGUID = UnityEditor.AssetDatabase.AssetPathToGUID(assetPath);
AssetType = UnityEditor.AssetDatabase.GetMainAssetTypeAtPath(assetPath);
if (AssetType == typeof(UnityEngine.Shader) || AssetType == typeof(UnityEngine.ShaderVariantCollection))
IsShaderAsset = true;
else
IsShaderAsset = false;
}

View File

@ -278,21 +278,22 @@ namespace YooAsset.Editor
return adressValue;
}
private string GetBundleName(CollectCommand command, AssetBundleCollectorGroup group, string assetPath)
{
if (command.AutoCollectShaders)
{
System.Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
if (assetType == typeof(UnityEngine.Shader) || assetType == typeof(UnityEngine.ShaderVariantCollection))
{
// 获取着色器打包规则结果
PackRuleResult packRuleResult = DefaultPackRule.CreateShadersPackRuleResult();
return packRuleResult.GetBundleName(command.PackageName, command.UniqueBundleName);
PackRuleResult shaderPackRuleResult = DefaultPackRule.CreateShadersPackRuleResult();
return shaderPackRuleResult.GetBundleName(command.PackageName, command.UniqueBundleName);
}
else
{
}
// 获取其它资源打包规则结果
IPackRule packRuleInstance = AssetBundleCollectorSettingData.GetPackRuleInstance(PackRuleName);
PackRuleResult packRuleResult = packRuleInstance.GetPackRuleResult(new PackRuleData(assetPath, CollectPath, group.GroupName, UserData));
return packRuleResult.GetBundleName(command.PackageName, command.UniqueBundleName);
}
PackRuleResult defaultPackRuleResult = packRuleInstance.GetPackRuleResult(new PackRuleData(assetPath, CollectPath, group.GroupName, UserData));
return defaultPackRuleResult.GetBundleName(command.PackageName, command.UniqueBundleName);
}
private List<string> GetAssetTags(AssetBundleCollectorGroup group)
{

View File

@ -40,6 +40,11 @@ namespace YooAsset.Editor
/// </summary>
public bool IgnoreDefaultType = true;
/// <summary>
/// 自动收集所有着色器(所有着色器存储在一个资源包内)
/// </summary>
public bool AutoCollectShaders = true;
/// <summary>
/// 分组列表
/// </summary>

View File

@ -101,7 +101,12 @@ namespace YooAsset.Editor
// 创建资源收集命令
CollectCommand command = new CollectCommand(buildMode, packageName,
package.EnableAddressable, package.LocationToLower, package.IncludeAssetGUID, package.IgnoreDefaultType, UniqueBundleName);
package.EnableAddressable,
package.LocationToLower,
package.IncludeAssetGUID,
package.IgnoreDefaultType,
package.AutoCollectShaders,
UniqueBundleName);
// 获取收集的资源集合
CollectResult collectResult = new CollectResult(command);

View File

@ -27,18 +27,20 @@ namespace YooAsset.Editor
private VisualElement _helpBoxContainer;
private VisualElement _setting1Container;
private Button _globalSettingsButton;
private Button _packageSettingsButton;
private VisualElement _setting1Container;
private Toggle _showPackageToogle;
private Toggle _showEditorAliasToggle;
private Toggle _uniqueBundleNameToogle;
private VisualElement _setting3Container;
private Button _packageSettingsButton;
private VisualElement _setting2Container;
private Toggle _enableAddressableToogle;
private Toggle _locationToLowerToogle;
private Toggle _includeAssetGUIDToogle;
private Toggle _ignoreDefaultTypeToogle;
private Toggle _autoCollectShadersToogle;
private VisualElement _packageContainer;
private ListView _packageListView;
@ -91,10 +93,13 @@ namespace YooAsset.Editor
// 警示栏
_helpBoxContainer = root.Q("HelpBoxContainer");
// 公共设置相关
_setting1Container = root.Q("PublicContainer1");
_globalSettingsButton = root.Q<Button>("GlobalSettingsButton");
_globalSettingsButton.clicked += GlobalSettingsBtn_clicked;
_packageSettingsButton = root.Q<Button>("PackageSettingsButton");
_packageSettingsButton.clicked += PackageSettingsBtn_clicked;
// 公共设置相关
_setting1Container = root.Q("PublicContainer1");
_showPackageToogle = root.Q<Toggle>("ShowPackages");
_showPackageToogle.RegisterValueChangedCallback(evt =>
{
@ -115,9 +120,7 @@ namespace YooAsset.Editor
});
// 包裹设置相关
_setting3Container = root.Q("PublicContainer3");
_packageSettingsButton = root.Q<Button>("PackageSettingsButton");
_packageSettingsButton.clicked += PackageSettingsBtn_clicked;
_setting2Container = root.Q("PublicContainer2");
_enableAddressableToogle = root.Q<Toggle>("EnableAddressable");
_enableAddressableToogle.RegisterValueChangedCallback(evt =>
{
@ -162,6 +165,17 @@ namespace YooAsset.Editor
RefreshWindow();
}
});
_autoCollectShadersToogle = root.Q<Toggle>("AutoCollectShaders");
_autoCollectShadersToogle.RegisterValueChangedCallback(evt =>
{
var selectPackage = _packageListView.selectedItem as AssetBundleCollectorPackage;
if (selectPackage != null)
{
selectPackage.AutoCollectShaders = evt.newValue;
AssetBundleCollectorSettingData.ModifyPackage(selectPackage);
RefreshWindow();
}
});
// 配置修复按钮
var fixBtn = root.Q<Button>("FixButton");
@ -458,17 +472,22 @@ namespace YooAsset.Editor
}
else
{
_showPackageSettings = false;
_packageSettingsButton.SetEnabled(false);
if(_packageListView.itemsSource.Count == 0)
if (_packageListView.itemsSource.Count == 0)
_packageSettingsButton.text = $"Not Found Any Package !";
else
_packageSettingsButton.text = $"Package Setting";
}
if (_showPackageSettings)
_setting3Container.style.display = DisplayStyle.Flex;
{
_setting2Container.style.display = DisplayStyle.Flex;
}
else
_setting3Container.style.display = DisplayStyle.None;
{
_setting2Container.style.display = DisplayStyle.None;
}
}
private void RefreshHelpBoxTips()
{
@ -539,7 +558,6 @@ namespace YooAsset.Editor
{
_groupContainer.visible = false;
_collectorContainer.visible = false;
_showPackageSettings = false;
}
else
{
@ -952,8 +970,14 @@ namespace YooAsset.Editor
try
{
CollectCommand command = new CollectCommand(EBuildMode.SimulateBuild, _packageNameTxt.value,
_enableAddressableToogle.value, _locationToLowerToogle.value, _includeAssetGUIDToogle.value, _ignoreDefaultTypeToogle.value, _uniqueBundleNameToogle.value);
CollectCommand command = new CollectCommand(EBuildMode.SimulateBuild,
_packageNameTxt.value,
_enableAddressableToogle.value,
_locationToLowerToogle.value,
_includeAssetGUIDToogle.value,
_ignoreDefaultTypeToogle.value,
_autoCollectShadersToogle.value,
_uniqueBundleNameToogle.value);
collector.CheckConfigError();
collectAssetInfos = collector.GetAllCollectAssets(command, group);
}

View File

@ -8,7 +8,7 @@
<ui:VisualElement name="PublicContainer" style="background-color: rgb(79, 79, 79); flex-direction: column; border-left-width: 5px; border-right-width: 5px; border-top-width: 5px; border-bottom-width: 5px;">
<ui:VisualElement name="HelpBoxContainer" style="flex-grow: 1;" />
<ui:VisualElement name="GlobalSettingsContainer">
<ui:Button text="Global Settings" display-tooltip-when-elided="true" name="GlobalSettingsButton" />
<ui:Button text="Global Settings" name="GlobalSettingsButton" />
<ui:VisualElement name="PublicContainer1" style="flex-direction: row; flex-wrap: nowrap; height: 28px;">
<ui:Toggle label="Show Packages" name="ShowPackages" style="width: 196px; -unity-text-align: middle-left;" />
<ui:Toggle label="Show Editor Alias" name="ShowEditorAlias" style="width: 196px; -unity-text-align: middle-left;" />
@ -17,11 +17,12 @@
</ui:VisualElement>
<ui:VisualElement name="PackageSettingsContainer">
<ui:Button text="Package Settings" display-tooltip-when-elided="true" name="PackageSettingsButton" />
<ui:VisualElement name="PublicContainer3" style="flex-direction: row; flex-wrap: nowrap; height: 28px;">
<ui:VisualElement name="PublicContainer2" style="flex-direction: row; flex-wrap: nowrap; height: 28px;">
<ui:Toggle label="Enable Addressable" name="EnableAddressable" style="width: 196px; -unity-text-align: middle-left;" />
<ui:Toggle label="Location To Lower" name="LocationToLower" style="width: 196px; -unity-text-align: middle-left;" />
<ui:Toggle label="Include Asset GUID" name="IncludeAssetGUID" style="width: 196px; -unity-text-align: middle-left;" />
<ui:Toggle label="Ignore Default Type" name="IgnoreDefaultType" style="width: 196px; -unity-text-align: middle-left;" />
<ui:Toggle label="Auto Collect Shaders" name="AutoCollectShaders" value="true" style="width: 196px; -unity-text-align: middle-left;" />
</ui:VisualElement>
</ui:VisualElement>
</ui:VisualElement>

View File

@ -33,6 +33,11 @@ namespace YooAsset.Editor
/// </summary>
public bool IncludeAssetGUID { private set; get; }
/// <summary>
/// 自动收集所有着色器
/// </summary>
public bool AutoCollectShaders { private set; get; }
/// <summary>
/// 资源包名唯一化
/// </summary>
@ -44,7 +49,7 @@ namespace YooAsset.Editor
public string ShadersBundleName { private set; get; }
public CollectCommand(EBuildMode buildMode, string packageName, bool enableAddressable, bool locationToLower, bool includeAssetGUID, bool ignoreDefaultType, bool uniqueBundleName)
public CollectCommand(EBuildMode buildMode, string packageName, bool enableAddressable, bool locationToLower, bool includeAssetGUID, bool ignoreDefaultType, bool autoCollectShaders, bool uniqueBundleName)
{
BuildMode = buildMode;
PackageName = packageName;
@ -52,6 +57,7 @@ namespace YooAsset.Editor
LocationToLower = locationToLower;
IncludeAssetGUID = includeAssetGUID;
IgnoreDefaultType = ignoreDefaultType;
AutoCollectShaders = autoCollectShaders;
UniqueBundleName = uniqueBundleName;
// 着色器统一全名称