From 1ab047b5fdd933c38ba0519ec2e83a44512ea8d7 Mon Sep 17 00:00:00 2001
From: yyl <yyl>
Date: 星期四, 26 三月 2026 17:46:11 +0800
Subject: [PATCH] webgl代码合并 1
---
Main/ResModule/YooAssetService.cs | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 57 insertions(+), 2 deletions(-)
diff --git a/Main/ResModule/YooAssetService.cs b/Main/ResModule/YooAssetService.cs
index db8d5af..81bcaca 100644
--- a/Main/ResModule/YooAssetService.cs
+++ b/Main/ResModule/YooAssetService.cs
@@ -1,4 +1,4 @@
-// ============================================================================
+锘�// ============================================================================
// YooAssetService.cs 鈥� YooAsset 灏佽鏈嶅姟
// 瀹炵幇 IYooAssetService 鍜� IYooAssetBridge锛屾浛浠� AssetBundleUtility
// ============================================================================
@@ -171,6 +171,11 @@
}
Debug.Log($"[YooAssetService] Initialized {_packages.Count}/{allPkgs.Length} packages with PlayMode={playMode}. " +
$"Active: [{string.Join(", ", _packages.Keys)}]");
+
+#if UNITY_WEBGL
+ // WebGL 璇婃柇锛氳緭鍑烘瘡涓寘鐨� Manifest 鍜� Bundle 璇︽儏
+ DiagDumpPackageStatus();
+#endif
}
/// <summary>
@@ -450,7 +455,7 @@
var package = FindPackageForAsset(location);
- Debug.LogError($"[YooAssetService] LoadAssetAsync: Loading asset '{location}' of package '{package.PackageName}'.");
+ // Debug.LogError($"[YooAssetService] LoadAssetAsync: Loading asset '{location}' of package '{package.PackageName}'.");
return await ExecuteWithRetryAsync(async () =>
{
@@ -533,7 +538,17 @@
throw new InvalidOperationException($"LoadRawFileTextAsync failed for '{location}': {handle.LastError}");
}
+#if UNITY_ANDROID && !UNITY_EDITOR
+ // 鐪熸満锛歋treamingAssets鍦╝pk鍐咃紝闇�鐢║nityWebRequest璇诲彇
+ string filePath = handle.GetRawFilePath();
+ using var uwr = UnityEngine.Networking.UnityWebRequest.Get(filePath);
+ await uwr.SendWebRequest().ToUniTask(cancellationToken: ct);
+ if (uwr.result != UnityEngine.Networking.UnityWebRequest.Result.Success)
+ throw new InvalidOperationException($"LoadRawFileTextAsync UWR failed for '{location}': {uwr.error}");
+ return uwr.downloadHandler.text;
+#else
return handle.GetRawFileText();
+#endif
}, $"LoadRawFileTextAsync('{location}')", ct);
}
@@ -553,7 +568,17 @@
throw new InvalidOperationException($"LoadRawFileBytesAsync failed for '{location}': {handle.LastError}");
}
+#if UNITY_ANDROID && !UNITY_EDITOR
+ // 鐪熸満锛歋treamingAssets鍦╝pk鍐咃紝闇�鐢║nityWebRequest璇诲彇
+ string filePath = handle.GetRawFilePath();
+ using var uwr = UnityEngine.Networking.UnityWebRequest.Get(filePath);
+ await uwr.SendWebRequest().ToUniTask(cancellationToken: ct);
+ if (uwr.result != UnityEngine.Networking.UnityWebRequest.Result.Success)
+ throw new InvalidOperationException($"LoadRawFileBytesAsync UWR failed for '{location}': {uwr.error}");
+ return uwr.downloadHandler.data;
+#else
return handle.GetRawFileData();
+#endif
}, $"LoadRawFileBytesAsync('{location}')", ct);
}
@@ -788,5 +813,35 @@
var package = FindPackageForAsset(location);
return package.LoadAllAssetsSync<T>(location);
}
+
+#if UNITY_WEBGL
+ /// <summary>
+ /// WebGL 璇婃柇锛氳緭鍑烘瘡涓� YooAsset 鍖呯殑鍒濆鍖栫姸鎬佸拰璧勬簮鏁伴噺銆�
+ /// </summary>
+ private void DiagDumpPackageStatus()
+ {
+ var sb = new System.Text.StringBuilder();
+ sb.AppendLine("[YooAssetService][WebGL-Diag] Package status dump:");
+ foreach (var kv in _packages)
+ {
+ var pkg = kv.Value;
+ var status = pkg.InitializeStatus;
+ // 灏濊瘯鑾峰彇娓呭崟涓殑璧勬簮淇℃伅鏁伴噺
+ int assetCount = 0;
+ try
+ {
+ // GetAssetInfos 杩斿洖璇ュ寘鎵�鏈夎祫婧愪俊鎭�
+ var infos = pkg.GetAssetInfos(string.Empty);
+ assetCount = infos != null ? infos.Length : -1;
+ }
+ catch
+ {
+ assetCount = -1;
+ }
+ sb.AppendLine($" [{kv.Key}] status={status}, assetInfoCount={assetCount}");
+ }
+ Debug.Log(sb.ToString());
+ }
+#endif
}
}
--
Gitblit v1.8.0