| | |
| | | // ============================================================================ |
| | | // ============================================================================ |
| | | // YooAssetService.cs — YooAsset 封装服务 |
| | | // 实现 IYooAssetService 和 IYooAssetBridge,替代 AssetBundleUtility |
| | | // ============================================================================ |
| | |
| | | } |
| | | 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> |
| | |
| | | |
| | | 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 () => |
| | | { |
| | |
| | | throw new InvalidOperationException($"LoadRawFileTextAsync failed for '{location}': {handle.LastError}"); |
| | | } |
| | | |
| | | #if UNITY_ANDROID && !UNITY_EDITOR |
| | | // 真机:StreamingAssets在apk内,需用UnityWebRequest读取 |
| | | 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); |
| | | } |
| | | |
| | |
| | | throw new InvalidOperationException($"LoadRawFileBytesAsync failed for '{location}': {handle.LastError}"); |
| | | } |
| | | |
| | | #if UNITY_ANDROID && !UNITY_EDITOR |
| | | // 真机:StreamingAssets在apk内,需用UnityWebRequest读取 |
| | | 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); |
| | | } |
| | | |
| | |
| | | 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 |
| | | } |
| | | } |