| | |
| | | Debug.Log($"[YooAssetService] Initialized {_packages.Count}/{allPkgs.Length} packages with PlayMode={playMode}. " + |
| | | $"Active: [{string.Join(", ", _packages.Keys)}]"); |
| | | |
| | | #if UNITY_WEBGL |
| | | // WebGL 诊断:输出每个包的 Manifest 和 Bundle 详情 |
| | | // 诊断:输出每个包的状态(Debug 构建下始终输出,方便排查 location is invalid 等问题) |
| | | #if UNITY_DEBUG || UNITY_EDITOR || DEVELOPMENT_BUILD |
| | | DiagDumpPackageStatus(); |
| | | #endif |
| | | } |
| | |
| | | { |
| | | var packageName = YooAssetPackageConfig.GetPackageForLocation(location); |
| | | if (_packages.TryGetValue(packageName, out var package)) |
| | | { |
| | | // 在加载前检查 location 是否在该包的 Manifest 里,提前暴露问题 |
| | | if (!package.CheckLocationValid(location)) |
| | | { |
| | | // 收集所有包的 CheckLocationValid 结果 |
| | | var validIn = new System.Collections.Generic.List<string>(); |
| | | foreach (var kv in _packages) |
| | | if (kv.Value.CheckLocationValid(location)) validIn.Add(kv.Key); |
| | | |
| | | Debug.LogError( |
| | | $"[YooAssetService][★INVALID-LOCATION★] location='{location}' 路由到包='{packageName}'" + |
| | | $" 但 CheckLocationValid=False!\n" + |
| | | $" → 包状态: {package.InitializeStatus}\n" + |
| | | $" → 该资源在以下包中有效: [{(validIn.Count > 0 ? string.Join(", ", validIn) : "无")}]\n" + |
| | | $" → 可能原因: ①包未重新打包导致 Manifest 缺少此资源 ②资源路径拼写错误 ③包初始化失败 Manifest 为空"); |
| | | } |
| | | return package; |
| | | } |
| | | |
| | | // 路由到的包尚未初始化,回退到默认包 — 发出明确警告 |
| | | Debug.LogWarning($"[YooAssetService] Package '{packageName}' not available for location '{location}'. " + |
| | |
| | | return package.LoadAllAssetsSync<T>(location); |
| | | } |
| | | |
| | | #if UNITY_WEBGL |
| | | #if UNITY_WEBGL || UNITY_DEBUG || UNITY_EDITOR || DEVELOPMENT_BUILD |
| | | /// <summary> |
| | | /// WebGL 诊断:输出每个 YooAsset 包的初始化状态和资源数量。 |
| | | /// 诊断:输出每个 YooAsset 包的初始化状态和资源数量。 |
| | | /// </summary> |
| | | private void DiagDumpPackageStatus() |
| | | { |
| | | var sb = new System.Text.StringBuilder(); |
| | | sb.AppendLine("[YooAssetService][WebGL-Diag] Package status dump:"); |
| | | sb.AppendLine("[YooAssetService][Diag] Package status dump:"); |
| | | foreach (var kv in _packages) |
| | | { |
| | | var pkg = kv.Value; |
| | | var status = pkg.InitializeStatus; |
| | | // 尝试获取清单中的资源信息数量 |
| | | int assetCount = 0; |
| | | int assetTotalCount = -1; |
| | | int bundleTotalCount = -1; |
| | | string pkgVersion = "?"; |
| | | try |
| | | { |
| | | // GetAssetInfos 返回该包所有资源信息 |
| | | var infos = pkg.GetAssetInfos(string.Empty); |
| | | assetCount = infos != null ? infos.Length : -1; |
| | | var details = pkg.GetPackageDetails(); |
| | | assetTotalCount = details.AssetTotalCount; |
| | | bundleTotalCount = details.BundleTotalCount; |
| | | pkgVersion = details.PackageVersion ?? "null"; |
| | | } |
| | | catch |
| | | catch { } |
| | | sb.AppendLine($" [{kv.Key}] status={status}, assets={assetTotalCount}, bundles={bundleTotalCount}, version={pkgVersion}"); |
| | | } |
| | | Debug.Log(sb.ToString()); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 诊断指定 location 在哪个包里、是否能找到。 |
| | | /// 调用:YooAssetService.Instance.DiagCheckLocation("Assets/ResourcesOut/Config/Foo.txt") |
| | | /// </summary> |
| | | public void DiagCheckLocation(string location) |
| | | { |
| | | var sb = new System.Text.StringBuilder(); |
| | | sb.AppendLine($"[DiagCheckLocation] location='{location}'"); |
| | | string routedPkg = YooAssetPackageConfig.GetPackageForLocation(location); |
| | | sb.AppendLine($" 路由到包: '{routedPkg}'"); |
| | | |
| | | foreach (var kv in _packages) |
| | | { |
| | | var pkg = kv.Value; |
| | | bool valid = pkg.CheckLocationValid(location); |
| | | sb.AppendLine($" [{kv.Key}] CheckLocationValid={valid}, InitStatus={pkg.InitializeStatus}"); |
| | | } |
| | | Debug.Log(sb.ToString()); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 打印所有已初始化包的资源数和版本(排查 Manifest 未加载问题)。 |
| | | /// </summary> |
| | | public void DiagDumpAllPackages() |
| | | { |
| | | var sb = new System.Text.StringBuilder(); |
| | | sb.AppendLine("[DiagDumpAllPackages]"); |
| | | foreach (var kv in _packages) |
| | | { |
| | | var pkg = kv.Value; |
| | | int assetTotalCount = -1; |
| | | int bundleTotalCount = -1; |
| | | string pkgVersion = "?"; |
| | | try |
| | | { |
| | | assetCount = -1; |
| | | var details = pkg.GetPackageDetails(); |
| | | assetTotalCount = details.AssetTotalCount; |
| | | bundleTotalCount = details.BundleTotalCount; |
| | | pkgVersion = details.PackageVersion ?? "null"; |
| | | } |
| | | sb.AppendLine($" [{kv.Key}] status={status}, assetInfoCount={assetCount}"); |
| | | catch { } |
| | | sb.AppendLine($" [{kv.Key}] status={pkg.InitializeStatus}, assets={assetTotalCount}, bundles={bundleTotalCount}, version={pkgVersion}"); |
| | | } |
| | | Debug.Log(sb.ToString()); |
| | | } |