yyl
2026-03-26 1ab047b5fdd933c38ba0519ec2e83a44512ea8d7
Main/ResModule/ResManager.cs
@@ -189,10 +189,7 @@
    public async UniTask<T> LoadAssetAsync<T>(string directory, string name, bool needExt = true) where T : UnityEngine.Object
    {
        // 新版直接走 YooAsset/异步加载
        // 这里假设有 YooAssetService.Instance.LoadAssetAsync<T>(...) 可用
        string path = directory.EndsWith("/") ? directory + name : directory + "/" + name;
        return await YooAssetService.Instance.LoadAssetAsync<T>(path);
        return await LoadAssetAsync<T>(directory, name, needExt, CancellationToken.None);
    }
    private void LoadSpriteAsync<T>(string atlasName, string spriteName, Action<bool, UnityEngine.Object> callBack) where T : UnityEngine.Object
@@ -246,7 +243,9 @@
    public void UnloadAsset(string directory, string assetName)
    {
        string path = directory.EndsWith("/") ? directory + assetName : directory + "/" + assetName;
        directory = directory.Replace("\\", "/").TrimEnd('/');
        assetName = assetName.Replace("\\", "/");
        string path = ($"Assets/ResourcesOut/{directory}/{assetName}").Replace("//", "/");
        YooAssetService.Instance.UnloadAsset(path);
    }
@@ -289,7 +288,13 @@
        var path = ($"Assets/ResourcesOut/{directory}/{name}" + (needExt ? GetExtension(typeof(T)) : ""))
            .Replace("//", "/").Trim().Replace("\\", "/");
        // 音频文件扩展名统一转小写,避免 .WAV/.MP3 大小写不匹配
        if (typeof(T) == typeof(AudioClip))
        {
            var pathExt = System.IO.Path.GetExtension(path);
            if (!string.IsNullOrEmpty(pathExt) && pathExt != pathExt.ToLower())
                path = path.Substring(0, path.Length - pathExt.Length) + pathExt.ToLower();
        }
        if (!AssetSource.isUseAssetBundle)
        {
#if UNITY_EDITOR
@@ -312,7 +317,13 @@
        var path = ($"Assets/ResourcesOut/{directory}/{name}" + (needExt ? GetExtension(typeof(T)) : ""))
            .Replace("//", "/").Trim().Replace("\\", "/");
        // 音频文件扩展名统一转小写,避免 .WAV/.MP3 大小写不匹配
        if (typeof(T) == typeof(AudioClip))
        {
            var pathExt2 = System.IO.Path.GetExtension(path);
            if (!string.IsNullOrEmpty(pathExt2) && pathExt2 != pathExt2.ToLower())
                path = path.Substring(0, path.Length - pathExt2.Length) + pathExt2.ToLower();
        }
        if (!AssetSource.isUseAssetBundle)
        {
#if UNITY_EDITOR
@@ -336,7 +347,12 @@
        {
            var path = $"Assets/ResourcesOut/{atlasName}/{spriteName}.png"
                .Replace("//", "/").Trim().Replace("\\", "/");
            return await YooAssetService.Instance.LoadAssetAsync<Sprite>(path, ct: ct);
            var sprite = await YooAssetService.Instance.LoadAssetAsync<Sprite>(path, ct: ct);
#if UNITY_WEBGL
            if (sprite == null)
                Debug.LogWarning($"[ResManager][WebGL-Diag] Sprite load returned NULL: path={path}");
#endif
            return sprite;
        }
    }
@@ -344,12 +360,17 @@
    /// 异步加载配置文件(UniTask 版本)。
    /// AB 模式使用 YooAsset RawFile 异步加载,非 AB 模式直接读文件。
    /// </summary>
    public async UniTask<string[]> LoadConfigAsync(string name, CancellationToken ct = default)
    public async UniTask<string[]> LoadConfigAsync(string name, bool needExt = true, CancellationToken ct = default)
    {
        // AB 模式(含 WebGL): 使用 YooAsset 加载配置文件
        if (AssetSource.isUseAssetBundle)
        {
            var location = $"Assets/ResourcesOut/Config/{name}.txt";
            // 判断一下是否原来已经包含.txt 配合 needExt 做兼容,避免调用方传入重复后缀导致路径错误
            if (name.EndsWith(".txt") && needExt)
            {
                name = name.Substring(0, name.Length - 4);
            }
            var location = $"Assets/ResourcesOut/Config/{name}" + (needExt ? ".txt" : "");
            try
            {
#if UNITY_WEBGL
@@ -360,9 +381,9 @@
                if (asset != null && !string.IsNullOrEmpty(asset.text))
                    return asset.text.Split(new[] { "\r\n", "\n" }, System.StringSplitOptions.None);
#else
                var text = await ProjSG.Resource.YooAssetService.Instance.LoadRawFileTextAsync(location, ct);
                if (!string.IsNullOrEmpty(text))
                    return text.Split(new[] { "\r\n", "\n" }, System.StringSplitOptions.None);
                var textAsset = await ProjSG.Resource.YooAssetService.Instance.LoadAssetAsync<TextAsset>(location, 0, ct);
                if (textAsset != null && !string.IsNullOrEmpty(textAsset.text))
                    return textAsset.text.Split(new[] { "\r\n", "\n" }, System.StringSplitOptions.None);
#endif
            }
            catch (System.Exception ex)
@@ -374,7 +395,7 @@
        // 非 AB 模式: 直接读文件(Editor 开发模式)
#if UNITY_EDITOR
        string path = ResourcesPath.CONFIG_FODLER + "/" + name + ".txt";
        string path = ResourcesPath.CONFIG_FODLER + "/" + name + (needExt ? ".txt" : "");
        return await UniTask.RunOnThreadPool(() => File.ReadAllLines(path));
#else
        return System.Array.Empty<string>();