public bool IsDone(ref AssetBundleContext context, out GameAssetBundle assetBundle) { if (context.Cache.GetAssetBundle(AssetBundleName, out assetBundle)) { //异步请求还未完成 if (assetBundle.LoadRequest != null || assetBundle.LoadAssetRequest != null || assetBundle.SceneRequest != null || assetBundle.UnloadSceneRequest != null) { return(false); } if (AssetBundleConfig.IsSimulator()) { return(true); } ///被预加载pin住的 if (IsPreLoad() && PinTime > 0) { if (FinishTime > CreateTime) { return(Time.realtimeSinceStartup - FinishTime > PinTime); } return(false); } //正在下载的 if (AssetBundleFunction.InDowloading(ref context, ref this)) { return(false); } //加载异常 if (AssetBundleConfig.SafeMode && assetBundle.IsException()) { return(true); } else if (assetBundle.AssetStatus.HasEnum(AssetBundleStatus.InMemory)) //加载正常 { int finish; int total; return(IsSubAllDone(ref context, out finish, out total)); } //else if(assetBundle.AssetStatus == AssetBundleStatus.None)//啥事也没干的task //{ // return true; //} } else { return(true); } return(false); }
protected virtual void TryDoTask(ref AssetBundleContext context) { int loadcnt = Mathf.Max(1, AssetBundleConfig.TaskStep); int loaded = 0; for (int i = 0; i < context.Tasks.Count; i++) { var task = context.Tasks[i]; if (IsEnableTask(ref context, ref task)) { bool changed = true; bool indownloading = AssetBundleFunction.InDowloading(ref context, ref task); if (indownloading) { changed = false; } else { try { changed = LoadAssetBundle(ref context, ref task); } catch (Exception e) { Debug.LogError(e); changed = true; AddException(ref context, task.AssetPath); } } if (changed) { context.Tasks[i] = task; } if (task.IsPreLoad() || indownloading)//ignore { continue; } else//真实加载的才被记录 { loaded++; if (loaded >= loadcnt) { break; } } } } }