| | |
| | | // 避免同目录下同名不同扩展名文件的地址冲突 |
| | | // ============================================================================ |
| | | |
| | | using System; |
| | | using System.IO; |
| | | using YooAsset.Editor; |
| | | |
| | |
| | | { |
| | | string IAddressRule.GetAssetAddress(AddressRuleData data) |
| | | { |
| | | // 去掉 CollectPath 前缀,得到相对路径 |
| | | string relativePath = data.AssetPath; |
| | | string collectRoot = data.CollectPath; |
| | | string assetPath = NormalizeAssetPath(data.AssetPath); |
| | | string collectPath = NormalizeAssetPath(data.CollectPath).TrimEnd('/'); |
| | | |
| | | // 确保以 / 结尾 |
| | | if (!collectRoot.EndsWith("/")) |
| | | collectRoot += "/"; |
| | | if (assetPath.Equals(collectPath, StringComparison.OrdinalIgnoreCase)) |
| | | return Path.GetFileName(assetPath); |
| | | |
| | | if (relativePath.StartsWith(collectRoot)) |
| | | string collectRoot = collectPath + "/"; |
| | | if (assetPath.StartsWith(collectRoot, StringComparison.OrdinalIgnoreCase)) |
| | | { |
| | | relativePath = relativePath.Substring(collectRoot.Length); |
| | | return assetPath.Substring(collectRoot.Length); |
| | | } |
| | | |
| | | // 保留扩展名,避免同名不同类型文件地址冲突 |
| | | return relativePath; |
| | | return Path.GetFileName(assetPath); |
| | | } |
| | | |
| | | private static string NormalizeAssetPath(string assetPath) |
| | | { |
| | | return string.IsNullOrEmpty(assetPath) ? string.Empty : assetPath.Replace('\\', '/'); |
| | | } |
| | | } |