三国卡牌客户端基础资源仓库
yyl
2026-05-22 89e196208d89007a7b033b0e70488035ae61eb73
Assets/Editor/YooAsset/AddressByRelativePath.cs
@@ -4,6 +4,7 @@
// 避免同目录下同名不同扩展名文件的地址冲突
// ============================================================================
using System;
using System.IO;
using YooAsset.Editor;
@@ -20,20 +21,23 @@
{
    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('\\', '/');
    }
}