diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildAssetInfo.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildAssetInfo.cs index 057a1ed..80f3c77 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildAssetInfo.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildAssetInfo.cs @@ -31,6 +31,11 @@ namespace YooAsset.Editor /// public bool IsCollectAsset { private set; get; } + /// + /// 是否为着色器资源 + /// + public bool IsShaderAsset { private set; get; } + /// /// 被依赖次数 /// @@ -54,6 +59,12 @@ namespace YooAsset.Editor IsRawAsset = isRawAsset; NotWriteToAssetList = notWriteToAssetList; IsCollectAsset = true; + + System.Type assetType = UnityEditor.AssetDatabase.GetMainAssetTypeAtPath(assetPath); + if (assetType == typeof(UnityEngine.Shader)) + IsShaderAsset = true; + else + IsShaderAsset = false; } public BuildAssetInfo(string assetPath) { @@ -61,6 +72,12 @@ namespace YooAsset.Editor IsRawAsset = false; NotWriteToAssetList = true; IsCollectAsset = false; + + System.Type assetType = UnityEditor.AssetDatabase.GetMainAssetTypeAtPath(assetPath); + if (assetType == typeof(UnityEngine.Shader)) + IsShaderAsset = true; + else + IsShaderAsset = false; } /// @@ -82,7 +99,7 @@ namespace YooAsset.Editor if (string.IsNullOrEmpty(BundleName) == false) throw new System.Exception("Should never get here !"); - BundleName = bundleName; + BundleName = bundleName; } /// @@ -99,7 +116,7 @@ namespace YooAsset.Editor /// /// 添加资源分类标签 /// - public void AddAssetTag(string tag) + public void AddAssetTag(string tag) { if (AssetTags.Contains(tag) == false) { diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapHelper.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapHelper.cs index 526903c..598dcf7 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapHelper.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapHelper.cs @@ -26,7 +26,7 @@ namespace YooAsset.Editor { if (buildAssetDic.ContainsKey(collectAssetInfo.AssetPath) == false) { - var buildAssetInfo = new BuildAssetInfo(collectAssetInfo.AssetPath, collectAssetInfo.IsRawAsset, collectAssetInfo.NotWriteToAssetList); + var buildAssetInfo = new BuildAssetInfo(collectAssetInfo.AssetPath, collectAssetInfo.IsRawAsset, collectAssetInfo.NotWriteToAssetList); buildAssetInfo.SetBundleName(collectAssetInfo.BundleName); buildAssetInfo.AddAssetTags(collectAssetInfo.AssetTags); buildAssetDic.Add(collectAssetInfo.AssetPath, buildAssetInfo); @@ -78,6 +78,13 @@ namespace YooAsset.Editor var buildAssetInfo = pair.Value; if (buildAssetInfo.IsCollectAsset) continue; + + if (AssetBundleGrouperSettingData.Setting.AutoCollectShaders) + { + if (buildAssetInfo.IsShaderAsset) + continue; + } + if (buildAssetInfo.DependCount == 0) removeList.Add(buildAssetInfo); } @@ -93,9 +100,17 @@ namespace YooAsset.Editor var buildAssetInfo = pair.Value; if (buildAssetInfo.BundleNameIsValid() == false) { - string bundleName = defaultPackRule.GetBundleName(new PackRuleData(buildAssetInfo.AssetPath)); - bundleName = AssetBundleCollector.RevisedBundleName(bundleName, false); - buildAssetInfo.SetBundleName(bundleName); + string shaderBundleName = AssetBundleCollector.CollectShaderBundleName(buildAssetInfo.AssetPath); + if (string.IsNullOrEmpty(shaderBundleName) == false) + { + buildAssetInfo.SetBundleName(shaderBundleName); + } + else + { + string bundleName = defaultPackRule.GetBundleName(new PackRuleData(buildAssetInfo.AssetPath)); + bundleName = AssetBundleCollector.CorrectBundleName(bundleName, false); + buildAssetInfo.SetBundleName(bundleName); + } } } diff --git a/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleCollector.cs b/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleCollector.cs index 0a8f497..93b31d0 100644 --- a/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleCollector.cs +++ b/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleCollector.cs @@ -94,6 +94,7 @@ namespace YooAsset.Editor string bundleName = GetBundleName(grouper, assetPath, isRawAsset); List assetTags = GetAssetTags(grouper); var collectAssetInfo = new CollectAssetInfo(bundleName, assetPath, assetTags, isRawAsset, NotWriteToAssetList); + collectAssetInfo.DependAssets = GetAllDependencies(assetPath); result.Add(assetPath, collectAssetInfo); } else @@ -120,7 +121,7 @@ namespace YooAsset.Editor return false; string ext = System.IO.Path.GetExtension(assetPath); - if (ext == "" || ext == ".dll" || ext == ".cs" || ext == ".js" || ext == ".boo" || ext == ".meta") + if (ext == "" || ext == ".dll" || ext == ".cs" || ext == ".js" || ext == ".boo" || ext == ".meta" || ext == ".cginc") return false; return true; @@ -141,22 +142,15 @@ namespace YooAsset.Editor } private string GetBundleName(AssetBundleGrouper grouper, string assetPath, bool isRawAsset) { - // 如果收集全路径着色器 - if (AssetBundleGrouperSettingData.Setting.AutoCollectShaders) - { - System.Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath); - if (assetType == typeof(UnityEngine.Shader)) - { - string bundleName = AssetBundleGrouperSettingData.Setting.ShadersBundleName; - return RevisedBundleName(bundleName, false); - } - } + string shaderBundleName = CollectShaderBundleName(assetPath); + if (string.IsNullOrEmpty(shaderBundleName) == false) + return shaderBundleName; // 根据规则设置获取资源包名称 { IPackRule packRuleInstance = AssetBundleGrouperSettingData.GetPackRuleInstance(PackRuleName); string bundleName = packRuleInstance.GetBundleName(new PackRuleData(assetPath, CollectPath, grouper.GrouperName)); - return RevisedBundleName(bundleName, isRawAsset); + return CorrectBundleName(bundleName, isRawAsset); } } private List GetAssetTags(AssetBundleGrouper grouper) @@ -182,11 +176,28 @@ namespace YooAsset.Editor return result; } + /// + /// 收集着色器的资源包名称 + /// + public static string CollectShaderBundleName(string assetPath) + { + // 如果自动收集所有的着色器 + if (AssetBundleGrouperSettingData.Setting.AutoCollectShaders) + { + System.Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath); + if (assetType == typeof(UnityEngine.Shader)) + { + string bundleName = AssetBundleGrouperSettingData.Setting.ShadersBundleName; + return CorrectBundleName(bundleName, false); + } + } + return null; + } /// - /// 修正资源包名 + /// 修正资源包名称 /// - public static string RevisedBundleName(string bundleName, bool isRawBundle) + public static string CorrectBundleName(string bundleName, bool isRawBundle) { if (isRawBundle) {