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 Load(ref AssetBundleContext context, ref AssetBundleTask task, ref GameAssetBundle gameAssetBundle, ref bool retcode, bool mainloadrequest = false) { if (gameAssetBundle.IsException()) { return; } if (AssetBundleConfig.DebugMode.HasEnum(DebugMode.Detail)) { Debug.LogFormat("Load --- {0}", task); } gameAssetBundle.AssetStatus |= AssetBundleStatus.Loading; //not loaded if (gameAssetBundle.AssetBundle == null && gameAssetBundle.LoadRequest == null && gameAssetBundle.LoadAssetRequest == null) { if (IsEnableLoadAssetBunlde(ref context, ref task, ref gameAssetBundle)) { string assetfilename = AssetBundleConfig.Convert(task.AssetBundleName); string path = AssetBundleHelper.GetBundlePersistentPath(assetfilename); bool fileExist = File.Exists(path); string url; bool indownloadcache = context.Cache.TryGetDownloadUrl(new IgnoreCaseString(task.AssetBundleName), out url); bool canload = false; if (indownloadcache && !fileExist) { AssetDownloadInfo downloadInfo = new AssetDownloadInfo(); downloadInfo.AssetPath = task.AssetPath; downloadInfo.AssetBundleName = task.AssetBundleName; if (!context.DownLoadQueue.Contains(downloadInfo)) { downloadInfo.DstPath = path; downloadInfo.Url = url; downloadInfo.TaskId = task.TaskId; context.DownLoadQueue.Add(downloadInfo); } } else if (fileExist) { canload = true; } else if (!fileExist) { string streampath = AssetBundleHelper.GetBundleStreamPath(assetfilename); if (File.Exists(streampath)) { canload = true; path = streampath; } } if (canload) { if (task.IsAsync()) { gameAssetBundle.LoadRequest = AssetBundle.LoadFromFileAsync(path); if (AssetBundleConfig.DebugMode.HasEnum(DebugMode.Detail)) { Debug.LogFormat("LoadFromFileAsync AssetBundle :{0} ", task.AssetBundleName); } } else { gameAssetBundle.AssetBundle = AssetBundle.LoadFromFile(path); if (AssetBundleConfig.DebugMode.HasEnum(DebugMode.Detail)) { Debug.LogFormat("LoadFromFile AssetBundle :{0} ", task.AssetBundleName); } AfterLoadAssetBundle(ref context, ref task, ref gameAssetBundle, ref retcode, ref mainloadrequest); } } else if (!indownloadcache) { gameAssetBundle.AssetStatus |= AssetBundleStatus.FileNotExist; AddException(ref context, task.AssetPath); Debug.LogError(string.Format("cant load :{0}", task)); } } } else if (gameAssetBundle.LoadRequest != null)// in asyncing Load AssetBundle { if (gameAssetBundle.LoadRequest.isDone) { if (AssetBundleConfig.DebugMode.HasEnum(DebugMode.Detail)) { Debug.LogFormat("Async Task for Load AssetBundle is Done :{0} ", task); } gameAssetBundle.AssetBundle = gameAssetBundle.LoadRequest.assetBundle; AfterLoadAssetBundle(ref context, ref task, ref gameAssetBundle, ref retcode, ref mainloadrequest); gameAssetBundle.LoadRequest = null; } } else if (gameAssetBundle.LoadAssetRequest != null && mainloadrequest)// Load Asset { if (gameAssetBundle.LoadAssetRequest.isDone) { var loadfinishasset = gameAssetBundle.LoadAssetRequest.asset; if (loadfinishasset != null) { if (AssetBundleConfig.DebugMode.HasEnum(DebugMode.Detail)) { Debug.LogFormat("Async Task Add Asset :{0} ", task); } gameAssetBundle.AddAsset(task.AssetPath, gameAssetBundle.LoadAssetRequest.asset); gameAssetBundle.AssetStatus |= AssetBundleStatus.InMemory; if (task.Result.ProgresCallback != null) { ProgressArgs progressArgs = new ProgressArgs(1, 0, task.AssetPath, true); task.Result.ProgresCallback(ref progressArgs); } task.FinishTime = Time.realtimeSinceStartup; retcode = true; } else { Debug.LogErrorFormat("{0} has 0 Assets", gameAssetBundle.AssetBundle); gameAssetBundle.AssetStatus |= AssetBundleStatus.NotInMemory; } gameAssetBundle.LoadAssetRequest = null; } } else { if (mainloadrequest) { LoadMainAsset(ref context, ref task, ref gameAssetBundle, ref retcode); } } }