From 51b0f6ed9f4e1d3bb6f8144470b46908c7699a96 Mon Sep 17 00:00:00 2001
From: yyl <yyl>
Date: 星期一, 11 五月 2026 16:20:37 +0800
Subject: [PATCH] Merge branch 'master' into h5version

---
 Main/ResModule/ResManager.cs |  316 +++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 261 insertions(+), 55 deletions(-)

diff --git a/Main/ResModule/ResManager.cs b/Main/ResModule/ResManager.cs
index 4c5ce0b..88f84ee 100644
--- a/Main/ResModule/ResManager.cs
+++ b/Main/ResModule/ResManager.cs
@@ -1,15 +1,15 @@
-锘縰sing UnityEngine;
-using System.Collections;
+using UnityEngine;
 using System.Collections.Generic;
-using Cysharp.Threading.Tasks;
 using System;
 using UnityEngine.U2D;
-using LitJson;
 using System.IO;
-using UnityEngine.Networking;
 using UnityEngine.Video;
-using System.Reflection;
-
+using Spine.Unity;
+using UnityEngine.UI;
+using Cysharp.Threading.Tasks;
+using System.Threading;
+using ProjSG.Resource;
+using YooAsset;
 
 
 #if UNITY_EDITOR
@@ -69,7 +69,8 @@
     {
         {typeof(GameObject), "prefab"},
         {typeof(Sprite), "png"},
-        {typeof(Texture2D), "png"},
+        {typeof(Texture2D), "jpg"},
+        {typeof(Texture), "jpg"},
         {typeof(Shader), "shader"},
         {typeof(TextAsset), "txt"},
         {typeof(AudioClip), "wav"},
@@ -77,12 +78,13 @@
         {typeof(Material), "mat"},
         {typeof(VideoClip), "mp4"},
         {typeof(SpriteAtlas), "spriteatlasv2"},
+        {typeof(SkeletonDataAsset), "asset"},
     };
 
 
     public void Init()
     {
-
+        
     }
 
     public void Release()
@@ -125,35 +127,48 @@
     }
 #endif
 
-    public T LoadAsset<T> (string directory, string name) where T : UnityEngine.Object
+    // ====================================================================
+    // 鍚屾鏂规硶锛堜粎闈� WebGL 骞冲彴锛�
+    // ====================================================================
+#if !UNITY_WEBGL
+    //needExt 鏄惁闇�瑕佸嚱鏁板唴閮ㄦ坊鍔犲悗缂�
+    public T LoadAsset<T>(string directory, string name, bool needExt = true) where T : UnityEngine.Object
     {
-        T asset = null;
+        directory = directory.Replace("\\", "/");
+        name = name.Replace("\\", "/");
         //  鐗规畩澶勭悊 鍥犱负鏈変竴灞傚浘闆嗙殑鍏崇郴 directory瑕佷紶鍏ョ殑搴旇鏄痑tlas鐨勫悕瀛�
         if (typeof(T) == typeof(Sprite))
         {
             return LoadSprite(directory, name) as T;
         }
+        else if (typeof(T) == typeof(SkeletonDataAsset))
+        {
+            //鏂囦欢鐩綍璋冩暣锛宯ame涓寘鍚簡璺緞
+            if (name.Contains("/"))
+            {
+                directory += name.Substring(0, name.LastIndexOf("/"));
+                name = name.Substring(name.LastIndexOf("/") + 1);
+            }
+        }
 
-        return LoadAssetInternal<T>(directory, name);
+        return LoadAssetInternal<T>(directory, name, needExt);
     }
 
-    private T LoadAssetInternal<T>(string directory, string name) where T : UnityEngine.Object
+    //needExt 鏄惁闇�瑕佸嚱鏁板唴閮ㄦ坊鍔犲悗缂�
+    private T LoadAssetInternal<T>(string directory, string name, bool needExt = true) where T : UnityEngine.Object
     {
         T asset = null;
+        var path = ($"Assets/ResourcesOut/{directory}/{name}" + (needExt ? GetExtension(typeof(T)) : "")).Replace("//", "/").Trim().Replace("\\", "/");
 
-        var path = ($"Assets/ResourcesOut/{directory}/{name}" + GetExtension(typeof(T))).Replace("//", "/").Trim().Replace("\\", "/");
-        if (AssetSource.uiFromEditor)
+        if (!AssetSource.isUseAssetBundle)
         {
 #if UNITY_EDITOR
-            //  TODO YYL 杩樻槸瑕佹壘鍒板瓧绗︿覆闂
-            path = System.Text.RegularExpressions.Regex.Replace(path, @"[\p{C}]", "");
             asset = UnityEditor.AssetDatabase.LoadAssetAtPath<T>(path);
 #endif
         }
         else
         {
-            var assetInfo = new AssetInfo(directory.ToLower(), name.ToLower());
-            asset = AssetBundleUtility.Instance.Sync_LoadAsset(assetInfo, typeof(T)) as T;
+            asset = YooAssetService.Instance.LoadAssetSync<T>(path);
         }
 
         if (asset == null)
@@ -164,52 +179,144 @@
         return asset;
     }
 
-    private Sprite LoadSprite(string atlasName, string spriteName)
+    public string[] LoadConfig(string name)
     {
-#if !UNITY_EDITOR
-        SpriteAtlas atlas = LoadAsset<SpriteAtlas>("Sprite", atlasName.Replace("Sprite/", ""));
-        return atlas.GetSprite(spriteName);
-#else
-        return ResManager.Instance.LoadAssetInternal<Sprite>(atlasName, spriteName);
+#if UNITY_EDITOR
+        if (!AssetSource.isUseAssetBundle)
+        {
+            string path = ResourcesPath.CONFIG_FODLER + "/" + name + ".txt";
+            return File.ReadAllLines(path);
+        }
 #endif
+        // AB 妯″紡锛氶�氳繃 YooAsset 鍚屾鍔犺浇 TextAsset
+        var location = $"Assets/ResourcesOut/Config/{name}.txt";
+        var textAsset = YooAssetService.Instance.LoadAssetSync<TextAsset>(location);
+        if (textAsset != null && !string.IsNullOrEmpty(textAsset.text))
+            return textAsset.text.Split(new[] { "\r\n", "\n" }, StringSplitOptions.None);
+        Debug.LogError($"[ResManager] LoadConfig failed for '{name}'");
+        return Array.Empty<string>();
     }
 
-    public void LoadAssetAsync<T>(string directory, string name, Action<bool, UnityEngine.Object> callBack) where T : UnityEngine.Object
+    private Sprite LoadSprite(string atlasName, string spriteName)
     {
+        if (!AssetSource.isUseAssetBundle)
+        {
+            SpriteAtlas atlas = LoadAsset<SpriteAtlas>("Sprite", atlasName.Replace("Sprite/", ""));
+            if (null == atlas)
+            {
+                return null;
+            }
+            return atlas.GetSprite(spriteName);
+        }
+        else
+        {
+            // YooAsset 浣跨敤瀹屾暣璺緞鐩存帴鍔犺浇 Sprite
+            var path = $"Assets/ResourcesOut/{atlasName}/{spriteName}.png".Replace("//", "/");
+            return YooAssetService.Instance.LoadAssetSync<Sprite>(path);
+        }
+    }
+#endif
+
+    // ====================================================================
+    // 寮傛鍔犺浇鏂规硶锛堟墍鏈夊钩鍙扮粺涓�锛�
+    // ====================================================================
+
+    //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瑕佷紶鍏ョ殑搴旇鏄痑tlas鐨勫悕瀛�
         if (typeof(T) == typeof(Sprite))
         {
             LoadSpriteAsync<T>(directory, name, callBack);
             return;
         }
+        else if (typeof(T) == typeof(SkeletonDataAsset))
+        {
+            //鏂囦欢鐩綍璋冩暣锛宯ame涓寘鍚簡璺緞
+            if (name.Contains("/"))
+            {
+                directory += name.Substring(0, name.LastIndexOf("/"));
+                name = name.Substring(name.LastIndexOf("/") + 1);
+            }
+        }
 
-        LoadAssetAsyncInternal<T>(directory, name, callBack);
+        LoadAssetAsyncInternal<T>(directory, name, callBack, needExt);
     }
+
+    public async UniTask<T> LoadAssetAsync<T>(string directory, string name) where T : UnityEngine.Object
+    {
+        return await LoadAssetAsync<T>(directory, name, needExt: true);
+    }
+
+    public async UniTask<T> LoadAssetAsync<T>(string directory, string name, bool needExt = true, CancellationToken ct = default) where T : UnityEngine.Object
+    {
+        directory = directory.Replace("\\", "/");
+        name = name.Replace("\\", "/");
+
+        if (typeof(T) == typeof(Sprite))
+        {
+            return await LoadSpriteAsyncUniTask(directory, name, ct) as T;
+        }
+
+        if (typeof(T) == typeof(SkeletonDataAsset))
+        {
+            if (name.Contains("/"))
+            {
+                directory += name.Substring(0, name.LastIndexOf("/"));
+                name = name.Substring(name.LastIndexOf("/") + 1);
+            }
+        }
+
+        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
+            return UnityEditor.AssetDatabase.LoadAssetAtPath<T>(path);
+#else
+            return null;
+#endif
+        }
+
+        return await YooAssetService.Instance.LoadAssetAsync<T>(path, ct: ct);
+    }
+
+    // ====================================================================
+    // 寮傛鍐呴儴瀹炵幇锛堢粺涓�锛�
+    // ====================================================================
 
     private void LoadSpriteAsync<T>(string atlasName, string spriteName, Action<bool, UnityEngine.Object> callBack) where T : UnityEngine.Object
     {
-#if !UNITY_EDITOR
-        LoadAssetAsync<SpriteAtlas>(atlasName, spriteName, (isLoaded, atlas) => {
-            if (isLoaded)
+        if (!AssetSource.isUseAssetBundle)
+        {
+            // Editor 妯″紡涓嬪彲鐩存帴鍔犺浇 sprite
+            LoadAssetAsyncInternal<T>(atlasName, spriteName, callBack);
+        }
+        else
+        {
+            // AB 妯″紡涓嬬洿鎺ュ姞杞藉崟鐙殑 Sprite 鏂囦欢锛圷ooAsset 鑷姩澶勭悊 SpriteAtlas 渚濊禆锛�
+            LoadAssetAsyncInternal<Sprite>(atlasName, spriteName, (isLoaded, sprite) =>
             {
-                callBack?.Invoke(isLoaded, atlas.GetSprite(spriteName));
-            }
-            else
-            {
-                callBack?.Invoke(false, null);
-            }
-        });
-#else
-        //  缂栬緫鍣ㄤ笅鍙互鐩存帴鍔犺浇娌″暐闂
-        LoadAssetAsyncInternal<T>(atlasName, spriteName, callBack);
-#endif
+                callBack?.Invoke(isLoaded, sprite);
+            });
+        }
     }
 
-    private void LoadAssetAsyncInternal<T>(string directory, string name, Action<bool, UnityEngine.Object> callBack) where T : UnityEngine.Object
+    private void LoadAssetAsyncInternal<T>(string directory, string name, Action<bool, UnityEngine.Object> callBack, bool needExt = true) where T : UnityEngine.Object
     {
-        var path = string.Concat($"Assets/ResourcesOut/{directory}/{name}", GetExtension(typeof(T))).Replace("//", "/");
+        var path = string.Concat($"Assets/ResourcesOut/{directory}/{name}", (needExt ? GetExtension(typeof(T)) : "")).Replace("//", "/");
 
-        if (AssetSource.uiFromEditor)
+        if (!AssetSource.isUseAssetBundle)
         {
 #if UNITY_EDITOR
             var asset = UnityEditor.AssetDatabase.LoadAssetAtPath<T>(path);
@@ -218,24 +325,33 @@
         }
         else
         {
-            var assetInfo = new AssetInfo(directory.ToLower(), name.ToLower());
-            AssetBundleUtility.Instance.Co_LoadAsset(assetInfo, callBack);
+            CoLoadViaYooAsset<T>(path, callBack).Forget();
         }
     }
 
-    public void UnloadAsset(string assetBundleName, string assetName)
+    private async UniTaskVoid CoLoadViaYooAsset<T>(string path, Action<bool, UnityEngine.Object> callBack, CancellationToken ct = default) where T : UnityEngine.Object
     {
-        if (AssetSource.uiFromEditor)
-            return;
-
-        AssetBundleUtility.Instance.UnloadAsset(assetBundleName, assetName);
+        try
+        {
+            var asset = await YooAssetService.Instance.LoadAssetAsync<T>(path, ct: ct);
+            callBack?.Invoke(asset != null, asset);
+        }
+        catch (Exception ex)
+        {
+            Debug.LogError($"[ResManager] Async load via YooAsset failed: {ex.Message}");
+            callBack?.Invoke(false, null);
+        }
     }
 
-    public void UnloadAssetBundle(string assetBundleName, bool unloadAllLoadedObjects, bool includeDependenice)
+    public void UnloadAsset(string directory, string assetName)
     {
-        if (AssetSource.uiFromEditor)
+        if (!AssetSource.isUseAssetBundle)
             return;
-        AssetBundleUtility.Instance.UnloadAssetBundle(assetBundleName, unloadAllLoadedObjects, includeDependenice);
+
+        directory = directory.Replace("\\", "/").TrimEnd('/');
+        assetName = assetName.Replace("\\", "/");
+        string path = ($"Assets/ResourcesOut/{directory}/{assetName}").Replace("//", "/");
+        YooAssetService.Instance.UnloadAsset(path);
     }
 
     public string GetAssetFilePath(string _assetKey)
@@ -249,5 +365,95 @@
         return path;
     }
 
+    // ====================================================================
+    // LoadConfigAsync锛堟墍鏈夊钩鍙扮粺涓�锛�
+    // ====================================================================
 
-}
\ No newline at end of file
+    /// <summary>
+    /// 寮傛鍔犺浇閰嶇疆鏂囦欢銆�
+    /// AB 妯″紡浣跨敤 YooAsset 寮傛鍔犺浇 TextAsset锛岄潪 AB 妯″紡鐩存帴璇绘枃浠躲��
+    /// </summary>
+    public async UniTask<string[]> LoadConfigAsync(string name, bool needExt = true, CancellationToken ct = default)
+    {
+        if (AssetSource.isUseAssetBundle)
+        {
+            if (name.EndsWith(".txt") && needExt)
+            {
+                name = name.Substring(0, name.Length - 4);
+            }
+            var location = $"Assets/ResourcesOut/Config/{name}" + (needExt ? ".txt" : "");
+            try
+            {
+                var asset = await YooAssetService.Instance.LoadAssetAsync(
+                    location, typeof(TextAsset), 0, ct) as TextAsset;
+                if (asset != null && !string.IsNullOrEmpty(asset.text))
+                    return asset.text.Split(new[] { "\r\n", "\n" }, StringSplitOptions.None);
+            }
+            catch (Exception ex)
+            {
+                Debug.LogError($"[ResManager] LoadConfigAsync YooAsset failed for '{name}': {ex.Message}");
+            }
+            return Array.Empty<string>();
+        }
+
+        // 闈� AB 妯″紡: 鐩存帴璇绘枃浠讹紙Editor 寮�鍙戞ā寮忥級
+#if UNITY_EDITOR
+        string path = ResourcesPath.CONFIG_FODLER + "/" + name + (needExt ? ".txt" : "");
+        return await UniTask.RunOnThreadPool(() => File.ReadAllLines(path));
+#else
+        return Array.Empty<string>();
+#endif
+    }
+
+    // ====================================================================
+    // 缂撳瓨鍔犺浇 & Sprite 寮傛鍔犺浇锛堟墍鏈夊钩鍙帮級
+    // ====================================================================
+
+    /// <summary>
+    /// 寮傛鍔犺浇璧勬簮骞惰蛋缂撳瓨灞傦紙缂撳瓨鍛戒腑鐩存帴杩斿洖锛屾湭鍛戒腑鍒欏姞杞藉苟缂撳瓨锛夈��
+    /// </summary>
+    public async UniTask<T> LoadAssetCachedAsync<T>(string directory, string name, bool needExt = true, CancellationToken ct = default) where T : UnityEngine.Object
+    {
+        directory = directory.Replace("\\", "/");
+        name = name.Replace("\\", "/");
+
+        var path = ($"Assets/ResourcesOut/{directory}/{name}" + (needExt ? GetExtension(typeof(T)) : ""))
+            .Replace("//", "/").Trim().Replace("\\", "/");
+        // 闊抽鏂囦欢鎵╁睍鍚嶇粺涓�杞皬鍐�
+        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
+            return UnityEditor.AssetDatabase.LoadAssetAtPath<T>(path);
+#else
+            return null;
+#endif
+        }
+
+        return await ResourceCacheManager.Instance.GetOrLoadAsync<T>(path);
+    }
+
+    private async UniTask<Sprite> LoadSpriteAsyncUniTask(string atlasName, string spriteName, CancellationToken ct = default)
+    {
+        if (!AssetSource.isUseAssetBundle)
+        {
+            var atlas = await LoadAssetAsync<SpriteAtlas>("Sprite", atlasName.Replace("Sprite/", ""), ct: ct);
+            return atlas?.GetSprite(spriteName);
+        }
+        else
+        {
+            var path = $"Assets/ResourcesOut/{atlasName}/{spriteName}.png"
+                .Replace("//", "/").Trim().Replace("\\", "/");
+            var sprite = await YooAssetService.Instance.LoadAssetAsync<Sprite>(path, ct: ct);
+            if (sprite == null)
+                Debug.LogWarning($"[ResManager] Sprite load returned NULL: path={path}");
+            return sprite;
+        }
+    }
+
+}

--
Gitblit v1.8.0