找物源码导读Cocos Creator 3.8 · assets/scripts
0%
已读 0 / 424
目录— 个文件
目录加载中…
…/resource/loader/ResourceAssetLoader.ts
1import { Asset, assetManager, AssetManager, SpriteFrame, Texture2D } from 'cc';
2import { Framework } from '../../../Framework';
3import { ResourceRetryConfig } from '../ResourceFrameConfig';
4import { ResourceInfo } from '../ResourceInfo';
5import { AssetType, CompleteCallback, ILoadResArgs, ProgressCallback } from "../ResourceTypeDefine";
6
7/**
8 * 单个加载调用的重试参数覆盖
9 */
10export interface RetryOptions {
11 /** 最大重试次数(覆盖全局 ResourceRetryConfig) */
12 maxRetryCount?: number;
13 /** 重试间隔(毫秒,覆盖全局配置) */
14 retryInterval?: number;
15 /** Bundle 加载完成后是否全量预加载该 Bundle 内所有资源 */
16 preloadAllBundleAssets?: boolean;
17}
18
19
20/**
21 * Asset 资源加载器(统一管理所有 Asset 加载逻辑)
22 */
23export class ResourceAssetLoader {
24
25 //资源缓存
26 private assetCache: Map<string, Asset> = new Map();
27
28 // 每帧调度的分帧预加载任务
29 private frameTickers: Set<() => void> = new Set();
30
31
32 /**
33 * 公共逻辑:检查缓存并获取资源配置信息
34 * @param assetName 资源名称
35 * @param onComplete 完成回调(用于缓存命中/配置不存在时直接返回)
36 * @returns 检查结果(是否需要继续加载 + 资源配置信息)
37 */
38 private CheckCacheAndResourceInfo<T extends Asset>(assetName: string, onComplete?: CompleteCallback, traceId?: number): {
39 shouldProceed: boolean;
40 resourceInfo?: ResourceInfo
41 } {
42 // 1. 检查缓存
43 const cachedAsset = this.GetAssetFromCache(assetName);
44 if (cachedAsset) {
45 Framework.Log.TraceLog(traceId ?? null, Framework.Res.Name + " ResourceAssetLoader", "CheckCacheAndResourceInfo", `资源缓存命中: ${assetName}`);
46 onComplete?.(null, cachedAsset as T);
47 return { shouldProceed: false }; // 无需继续加载
48 }
49
50 // 2. 获取资源配置信息
51 const resourceInfo = Framework.Res.GetResourceInfoByAssetName(assetName);
52 if (!resourceInfo) {
53 Framework.Log.TraceError(traceId ?? null, Framework.Res.Name + " ResourceAssetLoader", "CheckCacheAndResourceInfo", `资源配置不存在: ${assetName}`);
54 onComplete?.(new Error(`资源配置不存在: ${assetName}`), null);
55 return { shouldProceed: false }; // 无需继续加载
56 }
57
58 // 3. 需继续加载(返回资源配置)
59 return { shouldProceed: true, resourceInfo };
60 }
61
62 /**
63 * 预加载 Asset 资源(同步回调式)
64 * @param assetName 资源名称
65 * @param type 资源类型
66 * @param onProgress 预加载进度回调
67 * @param onComplete 预加载完成回调(资源已缓存)
68 * @param traceId 链路ID
69 * @param retryOpts 重试参数覆盖
70 */
71 public PreLoadAsset<T extends Asset>(assetName: string, type: AssetType<T>, onProgress?: ProgressCallback, onComplete?: CompleteCallback, traceId?: number, retryOpts?: RetryOptions): void {
72 const moduleName = Framework.Res.Name + " ResourceAssetLoader";
73
74 const checkResult = this.CheckCacheAndResourceInfo<T>(assetName, onComplete, traceId);
75 if (!checkResult.shouldProceed) return;
76
77 const startTime = Date.now();
78
79 const args: ILoadResArgs<T> = {
80 paths: checkResult.resourceInfo!.InBundlePath,
81 preload: true,
82 type: type,
83 onProgress: onProgress || null,
84 onComplete: (err, asset) => {
85 const cost = Date.now() - startTime;
86 if (err) {
87 Framework.Log.TraceError(
88 traceId ?? null,
89 moduleName,
90 "PreLoadAsset",
91 `预加载失败: ${assetName}, 耗时 ${cost} ms`,
92 err
93 );
94 } else {
95 Framework.Log.TraceLog(
96 traceId ?? null,
97 moduleName,
98 "PreLoadAsset",
99 `预加载成功: ${assetName}, 耗时 ${cost} ms`
100 );
101 }
102 onComplete?.(err, asset);
103 },
104 maxRetryCount: retryOpts?.maxRetryCount,
105 retryInterval: retryOpts?.retryInterval,
106 preloadAllBundleAssets: retryOpts?.preloadAllBundleAssets,
107 };
108
109 this.LoadFromBundle(checkResult.resourceInfo!.Bundle, args, traceId);
110 }
111
112 /**
113 * 预加载 Asset 资源(异步 Promise 式)
114 * @param assetName 资源名称
115 * @param type 资源类型
116 * @returns Promise<Asset> 预加载完成的资源(已缓存)
117 */
118 public PreLoadAssetAsync<T extends Asset>(assetName: string, type: AssetType<T>, traceId?: number, retryOpts?: RetryOptions): Promise<T> {
119 return new Promise((resolve, reject) => {
120 this.PreLoadAsset(assetName, type, null, (err, asset) => {
121 if (err) {
122 Framework.Log.TraceError(traceId ?? null, this.constructor.name, "PreLoadAssetAsync", `预加载失败: ${assetName}`, err);
123 reject(err);
124 return;
125 }
126 resolve(asset as T);
127 }, traceId, retryOpts);
128 });
129 }
130
131 /**
132 * 加载 Asset 资源(同步)
133 * @param assetName 资源名称
134 * @param type 资源类型
135 * @param onProgress 加载进度回调
136 * @param onComplete 加载完成回调
137 * @param traceId 链路ID
138 * @param retryOpts 重试参数覆盖
139 */
140 public LoadAsset<T extends Asset>(assetName: string, type: AssetType<T>, onProgress?: ProgressCallback, onComplete?: CompleteCallback, traceId?: number, retryOpts?: RetryOptions): void {
141 const moduleName = Framework.Res.Name + " ResourceAssetLoader";
142 Framework.Log.TraceLog(traceId ?? null, moduleName, "LoadAsset", `加载资源: ${assetName} 启动资源加载接口`);
143 const checkResult = this.CheckCacheAndResourceInfo<T>(assetName, onComplete, traceId);
144 if (!checkResult.shouldProceed) {
145 return;
146 }
147
148 const startTime = Date.now();
149
150 let args: ILoadResArgs<T> = {
151 paths: checkResult.resourceInfo!.InBundlePath,
152 preload: false,
153 type: type,
154 onProgress: onProgress || null,
155 onComplete: (err, asset) => {
156 const cost = Date.now() - startTime;
157 if (err) {
158 // Framework.Log.TraceError(
159 // traceId ?? null,
160 // moduleName,
161 // "LoadAsset",
162 // `资源加载失败: ${assetName}, 耗时 ${cost} ms`,
163 // err
164 // );
165 } else {
166 // Framework.Log.TraceLog(
167 // traceId ?? null,
168 // moduleName,
169 // "LoadAsset",
170 // `加载资源成功: ${assetName}, 耗时 ${cost} ms`
171 // );
172 this.assetCache.set(assetName, asset as T);
173 }
174 onComplete?.(err, asset);
175 },
176 maxRetryCount: retryOpts?.maxRetryCount,
177 retryInterval: retryOpts?.retryInterval,
178 preloadAllBundleAssets: retryOpts?.preloadAllBundleAssets,
179 };
180 this.LoadFromBundle(checkResult.resourceInfo!.Bundle, args, traceId);
181 }
182
183 /**
184 * 加载 Asset 资源(异步)
185 * @param assetName 资源名称
186 * @param type 资源类型
187 * @param onProgress 加载进度回调
188 * @param onComplete 加载完成回调
189 */
190 public LoadAssetAsync<T extends Asset>(assetName: string, type: AssetType<T>, onProgress?: ProgressCallback, onComplete?: CompleteCallback, traceId?: number, retryOpts?: RetryOptions): Promise<T> {
191 return new Promise<T>((resolve, reject) => {
192 this.LoadAsset(assetName, type, onProgress, (err, asset) => {
193 resolve(asset as T);
194 }, traceId, retryOpts);
195 });
196 }
197
198 /**
199 * 预加载目录资源(同步回调式)
200 * @param bundleName Bundle 名称
201 * @param dirPath 目录路径(Bundle 内相对路径)
202 * @param type 资源类型
203 * @param onProgress 预加载进度回调(可选)
204 * @param onComplete 预加载完成回调(可选)
205 * @param traceId 链路ID
206 * @param retryOpts 重试参数覆盖
207 */
208 public PreLoadDir(bundleName: string, dirPath: string, type: AssetType<Asset>, onProgress?: ProgressCallback, onComplete?: CompleteCallback, traceId?: number, retryOpts?: RetryOptions): void {
209 const args: ILoadResArgs<Asset> = {
210 dir: true,
211 paths: dirPath,
212 preload: true,
213 type: type,
214 onProgress: onProgress || null,
215 onComplete: onComplete || null,
216 maxRetryCount: retryOpts?.maxRetryCount,
217 retryInterval: retryOpts?.retryInterval,
218 preloadAllBundleAssets: retryOpts?.preloadAllBundleAssets,
219 };
220
221 this.LoadFromBundle(bundleName, args, traceId);
222 }
223
224 /**
225 * 分帧预加载目录资源(按小批次 + 限制并发,缓解卡顿)
226 */
227 public PreLoadDirByFrames(
228 bundleName: string,
229 dirPath: string,
230 type: AssetType<Asset>,
231 batchPerTick: number,
232 maxConcurrent: number,
233 onProgress?: (finished: number, total: number) => void,
234 onComplete?: () => void,
235 traceId?: number,
236 retryOpts?: RetryOptions,
237 ): void {
238 const moduleName = Framework.Res.Name + " ResourceAssetLoader";
239 const safeBatch = Math.max(1, batchPerTick || 1);
240 const safeConcurrent = Math.max(1, maxConcurrent || 1);
241
242 (async () => {
243 Framework.Log.TraceLog(traceId ?? null, moduleName, "PreLoadDirByFrames", `准备分帧预加载目录: ${bundleName}/${dirPath}`);
244 const bundle = await Framework.Res.BundleLoader.LoadBundle({
245 bundleName,
246 options: null,
247 traceId,
248 maxCount: retryOpts?.maxRetryCount,
249 retryTime: retryOpts?.retryInterval,
250 preloadAllBundleAssets: retryOpts?.preloadAllBundleAssets,
251 });
252 if (!bundle) {
253 Framework.Log.TraceError(traceId ?? null, moduleName, "PreLoadDirByFrames", `Bundle 加载失败: ${bundleName}`);
254 onComplete?.();
255 return;
256 }
257
258 const infos = bundle.getDirWithPath(dirPath);
259 if (!infos || infos.length === 0) {
260 Framework.Log.TraceLog(traceId ?? null, moduleName, "PreLoadDirByFrames", `目录为空或不存在: ${bundleName}/${dirPath}`);
261 onComplete?.();
262 return;
263 }
264
265 const total = infos.length;
266 let finished = 0;
267 let inFlight = 0;
268 const queue = infos.slice(); // 复制一份队列
269
270 const tryFinish = (tickFn: () => void) => {
271 if (finished >= total && queue.length === 0 && inFlight === 0) {
272 this.RemoveFrameTicker(tickFn);
273 onComplete?.();
274 }
275 };
276
277 const tick = () => {
278 let startedThisTick = 0;
279
280 while (startedThisTick < safeBatch && inFlight < safeConcurrent && queue.length > 0) {
281 const info = queue.shift()!;
282 inFlight++;
283 startedThisTick++;
284 const singleStart = Date.now();
285
286 bundle.preload(info.path, type as any, null, (err) => {
287 inFlight--;
288 finished++;
289 const singleCost = Date.now() - singleStart;
290 if (err) {
291 // Framework.Log.TraceError(
292 // traceId ?? null,
293 // moduleName,
294 // "PreLoadDirByFrames",
295 // `预加载单资源失败: ${bundleName}/${info.path}, 耗时 ${singleCost} ms`,
296 // err as any
297 // );
298 }
299 else {
300 // Framework.Log.TraceLog(
301 // traceId ?? null,
302 // moduleName,
303 // "PreLoadDirByFrames",
304 // `预加载单资源成功: ${bundleName}/${info.path}, 耗时 ${singleCost} ms`
305 // );
306 }
307
308 onProgress?.(finished, total);
309 tryFinish(tick);
310 });
311 }
312
313 // 队列已经为空且没有在飞任务时,尝试结束
314 if (queue.length === 0 && inFlight === 0) {
315 tryFinish(tick);
316 }
317 };
318
319 // 使用 ResourceManager.Update 驱动的每帧调度器
320 this.AddFrameTicker(tick);
321 })().catch((e) => {
322 Framework.Log.TraceError(traceId ?? null, moduleName, "PreLoadDirByFrames", `分帧预加载目录异常: ${bundleName}/${dirPath}`, e as any);
323 onComplete?.();
324 });
325 }
326
327 /**
328 * 加载 Asset 目录资源(异步)
329 * @param bundleName Bundle名称
330 * @param dirPath 资源目录路径
331 * @param type 资源类型
332 * @param onProgress 加载进度回调
333 * @param onComplete 加载完成回调
334 * @param traceId 链路ID
335 * @param retryOpts 重试参数覆盖
336 */
337 public LoadDir(bundleName: string, dirPath: string, type: AssetType<Asset>, onProgress?: ProgressCallback, onComplete?: CompleteCallback, traceId?: number, retryOpts?: RetryOptions): void {
338 let args: ILoadResArgs<Asset> = {
339 dir: true,
340 paths: dirPath,
341 preload: false,
342 type: type,
343 onProgress: onProgress || null,
344 onComplete: onComplete || null,
345 maxRetryCount: retryOpts?.maxRetryCount,
346 retryInterval: retryOpts?.retryInterval,
347 preloadAllBundleAssets: retryOpts?.preloadAllBundleAssets,
348 };
349 this.LoadFromBundle(bundleName, args, traceId);
350 }
351
352 /**
353 * 异步加载目录资源(Promise 式)
354 * @param bundleName Bundle 名称
355 * @param dirPath 目录路径(Bundle 内相对路径)
356 * @param type 资源类型
357 * @param onProgress 加载进度回调(可选)
358 * @returns Promise<Asset[] | null> 加载完成的资源数组
359 */
360 public LoadDirAsync(bundleName: string, dirPath: string, type: AssetType<Asset>, onProgress?: ProgressCallback, traceId?: number, retryOpts?: RetryOptions): Promise<Asset[] | null> {
361 return new Promise((resolve, reject) => {
362 this.LoadDir(bundleName, dirPath, type, onProgress, (err, assets) => {
363 if (err) {
364 Framework.Log.TraceError(traceId ?? null, this.constructor.name, "LoadDirAsync", `目录加载失败: ${bundleName}/${dirPath}`, err);
365 reject(err);
366 return;
367 }
368 resolve(assets as Asset[]);
369 }, traceId, retryOpts
370 );
371 });
372 }
373
374 /**
375 * 从 Bundle 加载资源(内置失败重试)
376 * maxRetryCount / retryInterval / preloadAllBundleAssets 优先取 args,未传则走全局配置
377 */
378 private async LoadFromBundle<T extends Asset>(bundleName: string, args: ILoadResArgs<T>, traceId?: number): Promise<void> {
379 const moduleName = Framework.Res.Name + " ResourceAssetLoader";
380 const maxRetry = args.maxRetryCount ?? ResourceRetryConfig.maxRetryCount;
381 const interval = args.retryInterval ?? ResourceRetryConfig.retryInterval;
382
383 Framework.Log.TraceLog(traceId ?? null, moduleName, "LoadFromBundle", `加载资源: ${bundleName}/${args.paths}`);
384
385 for (let attempt = 0; attempt <= maxRetry; attempt++) {
386 if (attempt > 0) {
387 Framework.Log.TraceLog(traceId ?? null, moduleName, "LoadFromBundle",
388 `重试第 ${attempt}/${maxRetry} 次加载资源: ${bundleName}/${args.paths}`);
389 await new Promise<void>(r => setTimeout(r, interval));
390 }
391
392 const bundle = await Framework.Res.BundleLoader.LoadBundle({
393 bundleName,
394 options: null,
395 traceId,
396 maxCount: args.maxRetryCount,
397 retryTime: args.retryInterval,
398 preloadAllBundleAssets: args.preloadAllBundleAssets,
399 });
400 if (!bundle) {
401 if (attempt >= maxRetry) {
402 break;
403 }
404 continue;
405 }
406
407 const result = await this.ExecuteAssetLoad<T>(bundle, args, traceId);
408 if (result.success) {
409 args.onComplete?.(null, result.asset as T);
410 return;
411 }
412
413 Framework.Log.TraceError(traceId ?? null, moduleName, "LoadFromBundle",
414 `第 ${attempt + 1} 次加载失败: ${bundleName}/${args.paths}`, result.error?.message);
415 }
416
417 args.onComplete?.(new Error(`资源加载失败(已重试 ${maxRetry} 次): ${bundleName}/${args.paths}`), null);
418 }
419
420 /**
421 * 执行单次 Asset 加载(从已加载的 Bundle 中加载资源)
422 */
423 private ExecuteAssetLoad<T extends Asset>(bundle: AssetManager.Bundle, args: ILoadResArgs<T>, traceId?: number): Promise<{ success: boolean; asset?: Asset; error?: Error | null }> {
424 return new Promise((resolve) => {
425 const wrappedComplete: CompleteCallback = (err, asset) => {
426 if (err) {
427 resolve({ success: false, error: err instanceof Error ? err : new Error(String(err)) });
428 } else {
429 resolve({ success: true, asset: asset as Asset });
430 }
431 };
432
433 if (args.dir) {
434 if (args.preload) {
435 bundle.preloadDir(args.paths as string, args.type, args.onProgress, wrappedComplete);
436 } else {
437 bundle.loadDir(args.paths as string, args.type, args.onProgress, wrappedComplete);
438 }
439 } else {
440 let modifiedPaths = args.paths as string;
441 if ((args.type as unknown) === Texture2D) {
442 modifiedPaths += '/texture';
443 } else if ((args.type as unknown) === SpriteFrame) {
444 modifiedPaths += '/spriteFrame';
445 }
446
447 if (args.preload) {
448 bundle.preload(modifiedPaths as any, args.type, args.onProgress, wrappedComplete);
449 } else {
450 bundle.load(modifiedPaths as any, args.type, args.onProgress, wrappedComplete);
451 }
452 }
453 });
454 }
455
456 /**
457 * 从缓存获取资源
458 */
459 private GetAssetFromCache(assetName: string): Asset | null {
460 const asset = this.assetCache.get(assetName);
461 // 缓存引用可能仍存在,但引擎资源已经失效,需要重新加载。
462 if (asset && !asset.isValid) {
463 this.assetCache.delete(assetName);
464 return null;
465 }
466 return asset || null;
467 }
468
469 /** 释放预制依赖资源 */
470 private ReleasePrefabtDepsRecursively(uuid: string | Asset) {
471 if (uuid instanceof Asset) {
472 if (!uuid.isValid) {
473 return;
474 }
475 assetManager.releaseAsset(uuid);
476 }
477 else {
478 if (!uuid) {
479 return;
480 }
481 const asset = assetManager.assets.get(uuid);
482 if (!asset || !asset.isValid) {
483 return;
484 }
485 assetManager.releaseAsset(asset);
486 }
487 }
488
489 /**
490 * 通过相对文件夹路径删除所有文件夹中资源
491 * @param path 资源文件夹路径
492 * @param bundleName 远程资源包名
493 */
494 ReleaseDir(path: string, bundleName: string) {
495 const bundle: AssetManager.Bundle | null = assetManager.getBundle(bundleName);
496 if (bundle) {
497 var infos = bundle.getDirWithPath(path);
498 if (infos) {
499 infos.map((info) => {
500 this.ReleasePrefabtDepsRecursively(info.uuid);
501 });
502 }
503
504 if (path == "" && bundleName != "resources") {
505 assetManager.removeBundle(bundle);
506 }
507 }
508 }
509
510 /**
511 * 释放单个资源
512 */
513 public ReleaseAsset(assetName: string): void {
514 const asset = this.assetCache.get(assetName);
515 if (!asset) {
516 return;
517 }
518 if (asset.isValid) {
519 this.ReleasePrefabtDepsRecursively(asset);
520 }
521 this.assetCache.delete(assetName);
522 }
523
524 /**
525 * 清理所有资源缓存(用于游戏重启)
526 */
527 public ReleaseAllAsset(): void {
528 this.assetCache.forEach((_, assetName) => this.ReleaseAsset(assetName));
529 this.assetCache.clear();
530 Framework.Log.Log(this.constructor.name, "ReleaseAllAsset", "所有资源缓存已清理");
531 }
532
533 /**
534 * 释放指定 Bundle 下的所有资源缓存(供 ResourceManager 调用)
535 */
536 public ReleaseBundleAssets(bundleName: string, getResourceInfo: (assetName: string) => ResourceInfo | null): void {
537 const releasedAssets: string[] = [];
538 this.assetCache.forEach((_, assetName) => {
539 const info = getResourceInfo(assetName);
540 if (info && info.Bundle === bundleName && info.Bundle !== "resources") {
541 this.ReleaseAsset(assetName);
542 releasedAssets.push(assetName);
543 }
544 });
545 Framework.Log.Log(this.constructor.name, "releaseBundleAssets", `释放 Bundle 资源缓存: ${bundleName}(共 ${releasedAssets.length} 个资源)`);
546 }
547
548 /**
549 * 每帧由 ResourceManager 驱动的更新,用于执行分帧预加载任务
550 */
551 public Update(deltaTime: number): void {
552 if (!this.frameTickers.size) return;
553 // 拷贝一份,避免执行过程中增删导致遍历问题
554 const tickers = Array.from(this.frameTickers);
555 for (const fn of tickers) {
556 fn();
557 }
558 }
559
560 private AddFrameTicker(fn: () => void): void {
561 this.frameTickers.add(fn);
562 }
563
564 private RemoveFrameTicker(fn: () => void): void {
565 this.frameTickers.delete(fn);
566 }
567}
讲解568 行
Asset 加载器人工通读

ResourceAssetLoader.ts

真正执行单资源与目录加载的组件,维护资源名到 Asset 的缓存,按 ResourceInfo 定位包与包内路径,并内置重试和分帧预加载。ResourceManager 的加载转发最终都落到这里,其 Update 由资源管理器每帧驱动。

先看 CheckCacheAndResourceInfo 的统一前置判断,再看 LoadAsset 与 PreLoadAsset 的差异,最后看 LoadFromBundle 重试与释放方法。

特殊处理与易错点

10注释单个加载调用的重试参数覆盖
12注释最大重试次数(覆盖全局 ResourceRetryConfig)
14注释重试间隔(毫秒,覆盖全局配置)
16注释Bundle 加载完成后是否全量预加载该 Bundle 内所有资源
23注释ResourceAssetLoader:Asset 资源加载器(统一管理所有 Asset 加载逻辑)
26属性资源名到 Asset 的缓存表,LoadAsset 成功写入,释放时删除,命中时直接回调。
29注释每帧调度的分帧预加载任务
38方法先查缓存命中即回调并停止,再查资源条目,条目缺失回调错误,命中则返回需继续加载。
39属性公共逻辑:检查缓存并获取资源配置信息
43注释1. 检查缓存
51注释2. 获取资源配置信息
59注释3. 需继续加载(返回资源配置)
71方法检查缓存与条目后构造预加载参数,带重试转入 Bundle 加载,成功后仅回调不写缓存。
118方法用 Promise 包装 PreLoadAsset,失败时 reject,成功时返回资源。
140方法检查缓存与条目后构造加载参数,加载成功后写入资源缓存并回调。
165注释Framework.Log.TraceError( traceId ?? null, moduleName, "LoadAsset", `资源加载失败: ${assetName}, 耗时 ${cost} ms`, err );
172注释Framework.Log.TraceLog( traceId ?? null, moduleName, "LoadAsset", `加载资源成功: ${assetName}, 耗时 ${cost} ms` );
190方法包装 LoadAsset,无论成功失败都 resolve,错误不会转成 reject。
208方法构造带目录标记的预加载参数,转交 Bundle 加载流程。
227方法先加载 Bundle 并取目录条目,再用每帧调度器按批次与并发限制逐个预加载。
298注释Framework.Log.TraceError( traceId ?? null, moduleName, "PreLoadDirByFrames", `预加载单资源失败: ${bundleName}/${info.path}, 耗时 ${singleCost} ms`, err as any );
306注释Framework.Log.TraceLog( traceId ?? null, moduleName, "PreLoadDirByFrames", `预加载单资源成功: ${bundleName}/${info.path}, 耗时 ${singleCost} ms` );
314注释队列已经为空且没有在飞任务时,尝试结束
320注释使用 ResourceManager.Update 驱动的每帧调度器
337方法构造带目录标记的加载参数,转交 Bundle 加载流程。
360方法包装 LoadDir,失败时 reject,成功时返回资源数组。
378方法循环加载 Bundle 并执行单次资源加载,失败重试,成功回调,耗尽后回传统一错误。
423方法把目录、预加载与类型子路径整理后调用 Bundle 对应接口,并把回调转成结果对象。
459方法读取缓存,资源已失效时删除条目并返回空,否则返回缓存资源。
462注释缓存引用可能仍存在,但引擎资源已经失效,需要重新加载。
470方法按资源对象或 uuid 找到有效资源后调用引擎 releaseAsset 释放。
494方法取 Bundle 目录条目逐个释放,路径为空且不是 resources 时移除整个 Bundle。
513方法从缓存取资源,有效则释放引擎资源,最后删除缓存条目。
527方法遍历缓存逐个释放后清空缓存表,并打印清理日志。
536方法遍历缓存按资源条目判断归属包,命中且不是 resources 时释放并计数。
551方法拷贝当前分帧任务集合后逐个执行,避免任务内部增删破坏遍历。
554注释拷贝一份,避免执行过程中增删导致遍历问题
560方法把分帧任务加入集合,等待 Update 每帧调度。
564方法把已完成的分帧任务从集合移除。