From 9e2030c83d4e50f228440b6d428384f11084ccab Mon Sep 17 00:00:00 2001 From: BoysheO <90881532+BoysheO@users.noreply.github.com> Date: Tue, 10 Sep 2024 11:36:46 +0800 Subject: [PATCH] Update DefaultAddressRule.cs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加一个寻址规则,效果极好 --- .../DefaultRules/DefaultAddressRule.cs | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/DefaultRules/DefaultAddressRule.cs b/Assets/YooAsset/Editor/AssetBundleCollector/DefaultRules/DefaultAddressRule.cs index 2a8da342..f158c9f7 100644 --- a/Assets/YooAsset/Editor/AssetBundleCollector/DefaultRules/DefaultAddressRule.cs +++ b/Assets/YooAsset/Editor/AssetBundleCollector/DefaultRules/DefaultAddressRule.cs @@ -40,4 +40,23 @@ string IAddressRule.GetAssetAddress(AddressRuleData data) return $"{fileInfo.Directory.Name}_{fileName}"; } } -} \ No newline at end of file + + [DisplayName("定位地址: 文件名.智能尾缀")] + public class AddressByFileNameAndExt : IAddressRule + { + public string GetAssetAddress(AddressRuleData data) + { + var ext = Path.GetExtension(data.AssetPath); + if (ext == ".asset") + { + var a = UnityEditor.AssetDatabase.LoadAssetAtPath(data.AssetPath); + if (a == null) return ".errortype"; + var type = a.GetType(); + var dt = Path.GetFileNameWithoutExtension(data.AssetPath); + return dt + $".{type.Name.ToLowerInvariant()}"; + } + + return Path.GetFileName(data.AssetPath); + } + } +}