public void Unload() { if (AppEnv.ResVerbose) { this.Msg($"unload bundle {PathIdProfile.Ins.GetPath(info.path)}"); } if (this.isLoading) { if (null != loadTask) { loadTask.Cancel(); loadTask = null; } this.isLoading = false; } else { ReleaseAsset(); if (null != bundle) { if (AppEnv.ResVerbose) { this.Msg($"bundle unloaded:{PathIdProfile.Ins.GetPath(info.path)}"); } bundle.Unload(true); bundle = null; } } mgr.RemoveHolder(info.path); }
private void RunTask(BundleLoadTask task) { if (null != task) { task.Start(); ++runningCount; runningTasks.Add(task); } }
private void TryLoadSelf() { if (this.IsLoaded() || null != loadTask || null == BundleLoader.Ins) //有可能出现,因为通过depend的回调有可能先执行到这,然后在StartLoaded执行到这 { return; } loadTask = new BundleLoadTask(this); BundleLoader.Ins.StartLoadTask(loadTask); }
protected void OnAssetSet(bool retry = false) { loadTask = null; //清除任务 bool needRetry = false; if (IsLoaded()) { //UObj.DontDestroyOnLoad(asset);//它的删除自己管理 if (retryTimes > 0) { this.Warning($"{retryTimes} times load {info.path} success"); } } else { this.Warning($"warning: {info.path} asset load null"); if (retry && retryTimes <= MAX_RETRY_TIMES) { needRetry = true; } } if (needRetry) { if (null != bundle) { this.Warning($"warning: {info.path} bundle release cause retry fail"); bundle.Unload(true); bundle = null; } ++retryTimes; TryLoadSelf(); } else { if (null != bundle) { if (!IsLoaded()) { this.Warning($"warning: {info.path} bundle unload cause asset no use"); bundle.Unload(true); bundle = null; } } isLoading = false; OnLoaded(); } }
private void CheckRunning() { for (int i = 0; i < runningCount;) { BundleLoadTask task = runningTasks[i]; if (task.IsFinished) { runningTasks.RemoveAt(i); --runningCount; } else { ++i; } } while (waitingTasks.Count > 0 && runningCount < BUNDLE_TASK_MAX) { RunTask(waitingTasks.Dequeue()); } }
public void StartLoadTask(BundleLoadTask task) { waitingTasks.Enqueue(task); }