From 1ad03cc2f91d75e80fc3dc42e2ac1fadc9a2bfec Mon Sep 17 00:00:00 2001
From: yyl <yyl>
Date: 星期三, 11 二月 2026 16:10:43 +0800
Subject: [PATCH] Merge branch 'master' into h5version
---
Main/ResModule/ResManager.cs | 276 +++++++++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 245 insertions(+), 31 deletions(-)
diff --git a/Main/ResModule/ResManager.cs b/Main/ResModule/ResManager.cs
index d5f3d4d..bdf5de0 100644
--- a/Main/ResModule/ResManager.cs
+++ b/Main/ResModule/ResManager.cs
@@ -1,13 +1,17 @@
-using UnityEngine;
-using System.Collections;
+锘縰sing 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 Spine.Unity;
+using UnityEngine.UI;
+using Cysharp.Threading.Tasks;
+using System.Threading;
+using ProjSG.Resource;
+
+
+
#if UNITY_EDITOR
@@ -67,7 +71,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"},
@@ -75,6 +80,7 @@
{typeof(Material), "mat"},
{typeof(VideoClip), "mp4"},
{typeof(SpriteAtlas), "spriteatlasv2"},
+ {typeof(SkeletonDataAsset), "asset"},
};
@@ -123,26 +129,38 @@
}
#endif
- public T LoadAsset<T> (string directory, string name) where T : UnityEngine.Object
+ //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
{
- 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 = string.Concat($"Assets/ResourcesOut/{directory}/{name}", GetExtension(typeof(T))).Replace("//", "/");
-
- if (AssetSource.uiFromEditor)
+ if (!AssetSource.isUseAssetBundle)
{
#if UNITY_EDITOR
asset = UnityEditor.AssetDatabase.LoadAssetAtPath<T>(path);
@@ -150,42 +168,132 @@
}
else
{
- var assetInfo = new AssetInfo(directory.ToLower(), name.ToLower());
- asset = AssetBundleUtility.Instance.Sync_LoadAsset(assetInfo, typeof(T)) as T;
+ // US1: Route through YooAssetService sync wrapper (transitional)
+ #pragma warning disable CS0612, CS0618
+ asset = YooAssetService.Instance.LoadAssetSync<T>(path);
+ #pragma warning restore CS0612, CS0618
}
if (asset == null)
{
- Debug.LogErrorFormat("LoadAsset() => 鍔犺浇涓嶅埌璧勬簮: {0}.", name);
+ Debug.LogErrorFormat("LoadAsset() => 鍔犺浇涓嶅埌璧勬簮: {0}", 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 !UNITY_EDITOR
- SpriteAtlas atlas = LoadAsset<SpriteAtlas>("Sprite", atlasName);
- return atlas.GetSprite(spriteName);
-#else
- // 缂栬緫鍣ㄤ笅鍙互鐩存帴鍔犺浇娌″暐闂
- return LoadAssetInternal<Sprite>("Sprite/" + atlasName, spriteName);
-#endif
+ 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);
+ }
+
+ private void LoadSpriteAsync<T>(string atlasName, string spriteName, Action<bool, UnityEngine.Object> callBack) where T : UnityEngine.Object
+ {
+ if (!AssetSource.isUseAssetBundle)
+ {
+ // Editor 妯″紡涓嬪彲鐩存帴鍔犺浇 sprite
+ LoadAssetAsyncInternal<T>(atlasName, spriteName, callBack);
+ }
+ else
+ {
+ // AB 妯″紡涓嬬洿鎺ュ姞杞藉崟鐙殑 Sprite 鏂囦欢锛圷ooAsset 鑷姩澶勭悊 SpriteAtlas 渚濊禆锛�
+ LoadAssetAsyncInternal<Sprite>(atlasName, spriteName, (isLoaded, sprite) =>
+ {
+ callBack?.Invoke(isLoaded, sprite);
+ });
+ }
+ }
+
+ 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}", (needExt ? GetExtension(typeof(T)) : "")).Replace("//", "/");
+
+ if (!AssetSource.isUseAssetBundle)
+ {
+#if UNITY_EDITOR
+ var asset = UnityEditor.AssetDatabase.LoadAssetAtPath<T>(path);
+ callBack?.Invoke(asset != null, asset);
+#endif
+ }
+ else
+ {
+ // US1: Route through YooAssetService async
+ CoLoadViaYooAsset<T>(path, callBack).Forget();
+ }
+ }
+
+ private async UniTaskVoid CoLoadViaYooAsset<T>(string path, Action<bool, UnityEngine.Object> callBack, CancellationToken ct = default) where T : UnityEngine.Object
+ {
+ 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);
+ }
+ }
+
+ [System.Obsolete("US1: Use YooAssetService.ReleaseHandle or UnloadUnusedAssetsAsync instead.")]
public void UnloadAsset(string assetBundleName, string assetName)
{
- if (AssetSource.uiFromEditor)
- return;
-
- AssetBundleUtility.Instance.UnloadAsset(assetBundleName, 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)
{
- if (AssetSource.uiFromEditor)
- return;
- AssetBundleUtility.Instance.UnloadAssetBundle(assetBundleName, unloadAllLoadedObjects, includeDependenice);
+ // US1: AssetBundleUtility unload no longer effective since assets loaded via YooAsset.
}
public string GetAssetFilePath(string _assetKey)
@@ -199,5 +307,111 @@
return path;
}
+ // ====================================================================
+ // US1: New UniTask-based async variants
+ // ====================================================================
+
+ /// <summary>
+ /// 寮傛鍔犺浇璧勬簮锛圲niTask 鐗堟湰锛孶S1 鏂板锛夈��
+ /// </summary>
+ 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("\\", "/");
+
+ 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);
+ }
+
+ /// <summary>
+ /// US4: 寮傛鍔犺浇璧勬簮骞惰蛋缂撳瓨灞傦紙缂撳瓨鍛戒腑鐩存帴杩斿洖锛屾湭鍛戒腑鍒欏姞杞藉苟缂撳瓨锛夈��
+ /// </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 (!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("\\", "/");
+ return await YooAssetService.Instance.LoadAssetAsync<Sprite>(path, ct: ct);
+ }
+ }
+
+ /// <summary>
+ /// 寮傛鍔犺浇閰嶇疆鏂囦欢锛圲niTask 鐗堟湰锛夈��
+ /// WebGL 骞冲彴浣跨敤 YooAsset RawFile 寮傛鍔犺浇锛屽叾浠栧钩鍙颁娇鐢ㄧ嚎绋嬫睜銆�
+ /// </summary>
+ public async UniTask<string[]> LoadConfigAsync(string name, CancellationToken ct = default)
+ {
+#if UNITY_WEBGL && !UNITY_EDITOR
+ // WebGL 涓嶆敮鎸佸绾跨▼鍜� File.ReadAllLines锛屼娇鐢� YooAsset RawFile
+ try
+ {
+ var text = await ProjSG.Resource.YooAssetService.Instance.LoadRawFileTextAsync($"config/{name}", ct);
+ if (!string.IsNullOrEmpty(text))
+ {
+ return text.Split(new[] { "\r\n", "\n" }, System.StringSplitOptions.None);
+ }
+ }
+ catch (System.Exception ex)
+ {
+ UnityEngine.Debug.LogError($"[ResManager] LoadConfigAsync WebGL fallback failed for '{name}': {ex.Message}");
+ }
+ return System.Array.Empty<string>();
+#else
+ #pragma warning disable CS0618 // LoadConfig is obsolete 鈥� used here as thread-pool fallback for non-WebGL
+ return await UniTask.RunOnThreadPool(() => LoadConfig(name));
+ #pragma warning restore CS0618
+#endif
+ }
}
\ No newline at end of file
--
Gitblit v1.8.0