//提交一个 同步加载请求 public void LoadRequest(LoadRequest req) { if (req == null) { return; } foreach (var task in req) { LoadTask(task); } OnRequestLoaded(req); }
//请求执行完后的回调 private void OnRequestLoaded(LoadRequest req) { foreach (var task in req) { AssetReference assetRef; if (TryGetAssetReference(task.LoadedAsset, out assetRef)) { assetRef.UnReference(); //释放Request带来的引用 } } if (!req.IsCancel) { req.CallAllLoaded(); } }
//提交一个 异步加载请求 public void LoadRequestAsync(LoadRequest req, LoadRequest.OnAllLoaded onLoaded = null) { if (req == null) { return; } //辅助写法,防止回调设置晚了 if (req.onAllLoaded == null && onLoaded != null) { req.onAllLoaded = onLoaded; } //Debug.Log("New Request"); _loadingQueue.AddLoadRequest(req); }
//将引用计数托管给GameObject public void ReferenceAssetsWithGo(GameObject go, LoadRequest request) { if (request == null || go == null) { return; } AssetReferenceComponent comp = TryGetAssetReferenceComponent(go); foreach (var task in request) { if (task.LoadedAsset != null) { ReferenceAssetWithGo(comp, task.LoadedAsset); } } }
public override IEnumerator Load() { while (_loadingQueue.Count > 0) { LoadRequest req = _loadingQueue.Dequeue(); if (req.IsDone || req.IsCancel) { continue; } //全部提交 foreach (LoadTask task in req) { LoadTask(task); } OnRequestLoaded(req); yield return(null); } }
public override IEnumerator Load() { while (_loadingQueue.Count > 0) { LoadRequest req = _loadingQueue.Dequeue(); if (req.IsDone || req.IsCancel) { continue; } //一次提交一个,加载完再次提交 foreach (LoadTask task in req) { LoadTaskAsync(task); yield return(new LoadTaskAsync(task)); //加载完一个任务后发现整个请求取消了 if (req.IsCancel) { break; } } OnRequestLoaded(req); } }
public LoadReqAsync(LoadRequest req) { Req = req; }
public void OnRequestLoaded(LoadRequest req) { this._onLoaded(req); }
public void AddLoadRequest(LoadRequest req) { _loadingQueue.Enqueue(req); }