From 636fbed7f2910bac168ee7419cfc046c4dc6da67 Mon Sep 17 00:00:00 2001 From: hevinci Date: Thu, 28 Apr 2022 22:16:34 +0800 Subject: [PATCH] Add new pack rule MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加一个新的打包规则:收集器目录下顶级文件夹收集器 --- .../AssetBundleGrouperSettingData.cs | 1 + .../AssetBundleGrouperWindow.cs | 49 ++++++++++++------- .../AssetBundleGrouper/DefaultPackRule.cs | 42 ++++++++++++++-- Assets/YooAsset/Editor/EditorTools.cs | 14 ------ 4 files changed, 70 insertions(+), 36 deletions(-) diff --git a/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperSettingData.cs b/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperSettingData.cs index 9cc7d8a..ee4a9d9 100644 --- a/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperSettingData.cs +++ b/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperSettingData.cs @@ -132,6 +132,7 @@ namespace YooAsset.Editor { typeof(PackSeparately), typeof(PackDirectory), + typeof(PackTopDirectory), typeof(PackCollector), typeof(PackGrouper), typeof(PackRawFile), diff --git a/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperWindow.cs b/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperWindow.cs index 7a6581a..601b13f 100644 --- a/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperWindow.cs +++ b/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperWindow.cs @@ -479,28 +479,41 @@ namespace YooAsset.Editor if (collector.IsValid() && collector.NotWriteToAssetList == false) { - var collectAssetInfos = collector.GetAllCollectAssets(grouper); - foreach (var collectAssetInfo in collectAssetInfos) + List collectAssetInfos = null; + + try { - VisualElement elementRow = new VisualElement(); - elementRow.style.flexDirection = FlexDirection.Row; - foldout.Add(elementRow); + collectAssetInfos = collector.GetAllCollectAssets(grouper); + } + catch(System.Exception e) + { + Debug.LogError(e.ToString()); + } - string showInfo = collectAssetInfo.AssetPath; - if (_enableAddressableToogle.value) + if(collectAssetInfos != null) + { + foreach (var collectAssetInfo in collectAssetInfos) { - IAddressRule instance = AssetBundleGrouperSettingData.GetAddressRuleInstance(collector.AddressRuleName); - AddressRuleData ruleData = new AddressRuleData(collectAssetInfo.AssetPath, collector.CollectPath, grouper.GrouperName); - string addressValue = instance.GetAssetAddress(ruleData); - showInfo = $"[{addressValue}] {showInfo}"; - } + VisualElement elementRow = new VisualElement(); + elementRow.style.flexDirection = FlexDirection.Row; + foldout.Add(elementRow); - var label = new Label(); - label.text = showInfo; - label.style.width = 300; - label.style.marginLeft = 0; - label.style.flexGrow = 1; - elementRow.Add(label); + string showInfo = collectAssetInfo.AssetPath; + if (_enableAddressableToogle.value) + { + IAddressRule instance = AssetBundleGrouperSettingData.GetAddressRuleInstance(collector.AddressRuleName); + AddressRuleData ruleData = new AddressRuleData(collectAssetInfo.AssetPath, collector.CollectPath, grouper.GrouperName); + string addressValue = instance.GetAssetAddress(ruleData); + showInfo = $"[{addressValue}] {showInfo}"; + } + + var label = new Label(); + label.text = showInfo; + label.style.width = 300; + label.style.marginLeft = 0; + label.style.flexGrow = 1; + elementRow.Add(label); + } } } } diff --git a/Assets/YooAsset/Editor/AssetBundleGrouper/DefaultPackRule.cs b/Assets/YooAsset/Editor/AssetBundleGrouper/DefaultPackRule.cs index 8480fac..386e516 100644 --- a/Assets/YooAsset/Editor/AssetBundleGrouper/DefaultPackRule.cs +++ b/Assets/YooAsset/Editor/AssetBundleGrouper/DefaultPackRule.cs @@ -7,30 +7,64 @@ namespace YooAsset.Editor /// /// 以文件路径作为资源包名 /// 注意:每个文件独自打资源包 + /// 例如:收集器路径为 "Assets/UIPanel" + /// 例如:"Assets/UIPanel/Shop/Image/backgroud.png" --> "assets/uipanel/shop/image/backgroud.bundle" + /// 例如:"Assets/UIPanel/Shop/View/main.prefab" --> "assets/uipanel/shop/view/main.bundle" /// public class PackSeparately : IPackRule { string IPackRule.GetBundleName(PackRuleData data) { - return StringUtility.RemoveExtension(data.AssetPath); //"Assets/Config/test.txt" --> "Assets/Config/test" + return StringUtility.RemoveExtension(data.AssetPath); } } /// /// 以父类文件夹路径作为资源包名 /// 注意:文件夹下所有文件打进一个资源包 + /// 例如:收集器路径为 "Assets/UIPanel" + /// 例如:"Assets/UIPanel/Shop/Image/backgroud.png" --> "assets/uipanel/shop/image.bundle" + /// 例如:"Assets/UIPanel/Shop/View/main.prefab" --> "assets/uipanel/shop/view.bundle" /// public class PackDirectory : IPackRule { string IPackRule.GetBundleName(PackRuleData data) { - return Path.GetDirectoryName(data.AssetPath); //"Assets/Config/test.txt" --> "Assets/Config" + return Path.GetDirectoryName(data.AssetPath); + } + } + + /// + /// 以收集器路径下顶级文件夹为资源包名 + /// 注意:文件夹下所有文件打进一个资源包 + /// 例如:收集器路径为 "Assets/UIPanel" + /// 例如:"Assets/UIPanel/Shop/Image/backgroud.png" --> "assets/uipanel/shop.bundle" + /// 例如:"Assets/UIPanel/Shop/View/main.prefab" --> "assets/uipanel/shop.bundle" + /// + public class PackTopDirectory : IPackRule + { + string IPackRule.GetBundleName(PackRuleData data) + { + string assetPath = data.AssetPath.Replace(data.CollectPath, string.Empty); + assetPath = assetPath.TrimStart('/'); + string[] splits = assetPath.Split('/'); + if (splits.Length > 0) + { + if (Path.HasExtension(splits[0])) + throw new Exception($"Not found root directory : {assetPath}"); + string bundleName = $"{data.CollectPath}/{splits[0]}"; + return bundleName; + } + else + { + throw new Exception($"Not found root directory : {assetPath}"); + } } } /// /// 以收集器路径作为资源包名 - /// 注意:收集器下所有文件打进一个资源包 + /// 注意:收集的所有文件打进一个资源包 /// public class PackCollector : IPackRule { @@ -42,7 +76,7 @@ namespace YooAsset.Editor /// /// 以分组名称作为资源包名 - /// 注意:分组内所有文件打进一个资源包 + /// 注意:收集的所有文件打进一个资源包 /// public class PackGrouper : IPackRule { diff --git a/Assets/YooAsset/Editor/EditorTools.cs b/Assets/YooAsset/Editor/EditorTools.cs index 0f77e0a..9b466db 100644 --- a/Assets/YooAsset/Editor/EditorTools.cs +++ b/Assets/YooAsset/Editor/EditorTools.cs @@ -582,19 +582,5 @@ namespace YooAsset.Editor return content.Substring(startIndex + key.Length); } #endregion - - #region 玩家偏好 - // 枚举 - public static void PlayerSetEnum(string key, T value) - { - string enumName = value.ToString(); - EditorPrefs.SetString(key, enumName); - } - public static T PlayerGetEnum(string key, T defaultValue) - { - string enumName = EditorPrefs.GetString(key, defaultValue.ToString()); - return StringUtility.NameToEnum(enumName); - } - #endregion } } \ No newline at end of file