hch
2026-03-31 862aeae51fdc2c8abd8753ac8d72c2ef2f07c03e
Main/ResModule/ResManager.cs
@@ -6,6 +6,8 @@
using UnityEngine.Video;
using Spine.Unity;
using UnityEngine.UI;
using Cysharp.Threading.Tasks;
@@ -129,6 +131,8 @@
    //needExt 是否需要函数内部添加后缀
    public T LoadAsset<T>(string directory, string name, bool needExt = true) where T : UnityEngine.Object
    {
        directory = directory.Replace("\\", "/");
        name = name.Replace("\\", "/");
        T asset = null;
        //  特殊处理 因为有一层图集的关系 directory要传入的应该是atlas的名字
        if (typeof(T) == typeof(Sprite))
@@ -144,7 +148,6 @@
                name = name.Substring(name.LastIndexOf("/") + 1);
            }
            directory = directory.Replace("\\", "/");
        }
        return LoadAssetInternal<T>(directory, name, needExt);
@@ -234,18 +237,48 @@
            return LoadAssetInternal<Sprite>(atlasName, spriteName);
    }
    //needExt 是否需要函数内部添加后缀
    public void LoadAssetAsync<T>(string directory, string name, Action<bool, UnityEngine.Object> callBack, bool needExt = true) where T : UnityEngine.Object
    {
        directory = directory.Replace("\\", "/");
        name = name.Replace("\\", "/");
        //  特殊处理 因为有一层图集的关系 directory要传入的应该是atlas的名字
        if (typeof(T) == typeof(Sprite))
        {
            LoadSpriteAsync<T>(directory, name, callBack);
            return;
        }
        else if (typeof(T) == typeof(SkeletonDataAsset))
        {
            //文件目录调整,name中包含了路径
            if (name.Contains("/"))
            {
                directory += name.Substring(0, name.LastIndexOf("/"));
                name = name.Substring(name.LastIndexOf("/") + 1);
            }
        }
        LoadAssetAsyncInternal<T>(directory, name, callBack, needExt);
    }
    public async UniTask<T> LoadAssetAsync<T>(string directory, string name, bool needExt = true) where T : UnityEngine.Object
    {
        var tcs = new UniTaskCompletionSource<T>();
        LoadAssetAsync<T>(directory, name, (isLoaded, asset) => {
            if (isLoaded)
            {
                tcs.TrySetResult(asset as T);
            }
            else
            {
                tcs.TrySetException(new Exception($"Failed to load asset: {directory}/{name}"));
            }
        }, needExt);
        return await tcs.Task;
    }
    private void LoadSpriteAsync<T>(string atlasName, string spriteName, Action<bool, UnityEngine.Object> callBack) where T : UnityEngine.Object
    {
#if !UNITY_EDITOR