From bc1cb6da854cb2e9144f10ed55330a537ecdca16 Mon Sep 17 00:00:00 2001
From: yyl <yyl>
Date: 星期三, 04 三月 2026 14:35:57 +0800
Subject: [PATCH] 466 h5版本 资源规则修改 打包修改(未完成 勿拉取)

---
 Main/ResModule/ResManager.cs |  190 ++++++++++++++++-------------------------------
 1 files changed, 65 insertions(+), 125 deletions(-)

diff --git a/Main/ResModule/ResManager.cs b/Main/ResModule/ResManager.cs
index 524efb3..8ec4613 100644
--- a/Main/ResModule/ResManager.cs
+++ b/Main/ResModule/ResManager.cs
@@ -9,6 +9,8 @@
 using Cysharp.Threading.Tasks;
 using System.Threading;
 using ProjSG.Resource;
+using YooAsset;
+
 
 
 
@@ -86,7 +88,7 @@
 
     public void Init()
     {
-
+        
     }
 
     public void Release()
@@ -129,110 +131,56 @@
     }
 #endif
 
-    //needExt 鏄惁闇�瑕佸嚱鏁板唴閮ㄦ坊鍔犲悗缂�
-    [System.Obsolete("US2: Use LoadAssetAsync<T>(directory, name, needExt) returning UniTask<T> instead.")]
-    public T LoadAsset<T>(string directory, string name, bool needExt = true) where T : UnityEngine.Object
-    {
-        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);
-            }
+    //  // needExt 鏄惁闇�瑕佸嚱鏁板唴閮ㄦ坊鍔犲悗缂�
+    // [System.Obsolete("US2: Use LoadAssetAsync<T>(directory, name, needExt) returning UniTask<T> instead.")]
+    // public T LoadAsset<T>(string directory, string name, bool needExt = true) where T : UnityEngine.Object
+    // {
+    //     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, needExt);
-    }
+    //     return LoadAssetInternal<T>(directory, name, needExt);
+    // }
 
-    //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("\\", "/");
+    // //needExt 鏄惁闇�瑕佸嚱鏁板唴閮ㄦ坊鍔犲悗缂�
+    // private T LoadAssetInternal<T>(string directory, string name, bool needExt = true) where T : UnityEngine.Object
+    // {
+    //     // 宸茬鐢ㄥ悓姝ュ姞杞斤紝寮哄埗涓氬姟鍏ㄩ儴璧板紓姝PI銆�
+    //     throw new NotSupportedException("鍚屾璧勬簮鍔犺浇宸茬鐢紝璇蜂娇鐢ㄥ紓姝ユ帴鍙�");
+    // }
 
-        if (!AssetSource.isUseAssetBundle)
-        {
-#if UNITY_EDITOR
-            asset = UnityEditor.AssetDatabase.LoadAssetAtPath<T>(path);
-#endif
-        }
-        else
-        {
-            // US1: Route through YooAssetService sync wrapper (transitional)
-            #pragma warning disable CS0612, CS0618
-            asset = YooAssetService.Instance.LoadAssetSync<T>(path);
-            #pragma warning restore CS0612, CS0618
-        }
+//     [System.Obsolete("US2: Use LoadConfigAsync returning UniTask<string[]> instead.")]
+//     public string[] LoadConfig(string name)
+//     {
+//         string path = string.Empty;
+// #if UNITY_EDITOR
+//         if (!AssetSource.isUseAssetBundle)
+//         {
+//             path = ResourcesPath.CONFIG_FODLER + "/" + name + ".txt";
+//         }
+//         else
+// #endif
+//         {
+//             path = AssetVersionUtility.GetAssetFilePath($"config/{name}.txt");
+//         }
 
-        if (asset == null)
-        {
-            Debug.LogErrorFormat("LoadAsset() => 鍔犺浇涓嶅埌璧勬簮: {0}", path);
-        }
+//         return File.ReadAllLines(path);
+//     }
 
-        return asset;
-    }
-
-    [System.Obsolete("US2: Use LoadConfigAsync returning UniTask<string[]> instead.")]
-    public string[] LoadConfig(string name)
-    {
-        string path = string.Empty;
-#if UNITY_EDITOR
-        if (!AssetSource.isUseAssetBundle)
-        {
-            path = ResourcesPath.CONFIG_FODLER + "/" + name + ".txt";
-        }
-        else
-#endif
-        {
-            path = AssetVersionUtility.GetAssetFilePath($"config/{name}.txt");
-        }
-
-        return File.ReadAllLines(path);
-    }
-
-    private Sprite LoadSprite(string atlasName, string spriteName)
-    {
-        if (!AssetSource.isUseAssetBundle)
-        {
-            #pragma warning disable CS0618 // Obsolete 鈥� legacy sync fallback
-            SpriteAtlas atlas = LoadAsset<SpriteAtlas>("Sprite", atlasName.Replace("Sprite/", ""));
-            #pragma warning restore CS0618
-            if (null == atlas)
-            {
-                return null;
-            }
-            return atlas.GetSprite(spriteName);
-        }
-        else
-            return LoadAssetInternal<Sprite>(atlasName, spriteName);
-    }
-
-    //needExt 鏄惁闇�瑕佸嚱鏁板唴閮ㄦ坊鍔犲悗缂�
-    [System.Obsolete("US2: Use LoadAssetAsync<T>(directory, name, needExt) returning UniTask<T> instead.")]
-    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;
-        }
-
-        LoadAssetAsyncInternal<T>(directory, name, callBack, needExt);
-    }
 
     public async UniTask<T> LoadAssetAsync<T>(string directory, string name) where T : UnityEngine.Object
     {
@@ -241,18 +189,10 @@
 
     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;
+        // 鏂扮増鐩存帴璧� YooAsset/寮傛鍔犺浇
+        // 杩欓噷鍋囪鏈� YooAssetService.Instance.LoadAssetAsync<T>(...) 鍙敤
+        string path = directory.EndsWith("/") ? directory + name : directory + "/" + name;
+        return await YooAssetService.Instance.LoadAssetAsync<T>(path);
     }
 
     private void LoadSpriteAsync<T>(string atlasName, string spriteName, Action<bool, UnityEngine.Object> callBack) where T : UnityEngine.Object
@@ -304,17 +244,10 @@
         }
     }
 
-    [System.Obsolete("US1: Use YooAssetService.ReleaseHandle or UnloadUnusedAssetsAsync instead.")]
-    public void UnloadAsset(string assetBundleName, string assetName)
+    public void UnloadAsset(string directory, string assetName)
     {
-        // US1: AssetBundleUtility unload no longer effective since assets loaded via YooAsset.
-        // Proper unload handled via YooAssetService handle-based release.
-    }
-
-    [System.Obsolete("US1: Use YooAssetService.UnloadUnusedAssetsAsync instead.")]
-    public void UnloadAssetBundle(string assetBundleName, bool unloadAllLoadedObjects, bool includeDependenice)
-    {
-        // US1: AssetBundleUtility unload no longer effective since assets loaded via YooAsset.
+        string path = directory.EndsWith("/") ? directory + assetName : directory + "/" + assetName;
+        YooAssetService.Instance.UnloadAsset(path);
     }
 
     public string GetAssetFilePath(string _assetKey)
@@ -413,17 +346,24 @@
     /// </summary>
     public async UniTask<string[]> LoadConfigAsync(string name, CancellationToken ct = default)
     {
-        // AB 妯″紡锛堝惈 WebGL锛�: 浣跨敤 YooAsset RawFile 鍔犺浇锛堥厤缃枃浠跺湪 YooAsset 娌欑洅涓級
+        // AB 妯″紡锛堝惈 WebGL锛�: 浣跨敤 YooAsset 鍔犺浇閰嶇疆鏂囦欢
         if (AssetSource.isUseAssetBundle)
         {
+            var location = $"Assets/ResourcesOut/Config/{name}.txt";
             try
             {
-                var location = $"Assets/ResourcesOut/Config/{name}.txt";
+#if UNITY_WEBGL
+                // WebGL: WebServerFileSystem 涓嶆敮鎸� LoadRawFileAsync锛屾敼鐢� LoadAssetAsync<TextAsset>
+                // .txt 鏂囦欢鍦� Unity 涓互 TextAsset 褰㈠紡瀵煎叆锛學ebGL 鏀寔姝ゅ姞杞芥柟寮�
+                var asset = await ProjSG.Resource.YooAssetService.Instance.LoadAssetAsync(
+                    location, typeof(UnityEngine.TextAsset), 0, ct) as UnityEngine.TextAsset;
+                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);
-                }
+#endif
             }
             catch (System.Exception ex)
             {

--
Gitblit v1.8.0