public void DownLoad(ref AssetDownloadInfo downloadInfo) { if (!downloadInfo.IsDone) { if (!downloadInfo.IsDownloading) { if (AssetBundleConfig.IsDetail()) { Debug.LogFormat("Start DownLoad :{0}", downloadInfo.Url); } GUpdater.mIns.StartCoroutine(DownLoadAssetBundle(downloadInfo.Url, downloadInfo.DstPath)); downloadInfo.IsDownloading = true; } } if (_cacherequest != null) { downloadInfo.IsDone = _cacherequest.isDone; downloadInfo.Progress = _cacherequest.downloadProgress; if (_cacherequest.isDone) { downloadInfo.HasError = !string.IsNullOrEmpty(_cacherequest.error) || _cacherequest.responseCode != 0; downloadInfo.IsDownloading = false; _cacherequest.Dispose(); _cacherequest = null; } } }
void DownLoadAssetBundle(ref AssetBundleContext context, ref AssetDownloadInfo downloadtask) { if (!downloadtask.IsDone && !downloadtask.IsDownloading) { downloadtask.Loader = AssetBundleTypeGetter.GetDownloader(); } //update downloadtask.Loader.DownLoad(ref downloadtask); if (downloadtask.TaskId >= 0) { for (int i = 0; i < context.Tasks.Count; i++) { var assettask = context.Tasks[i]; if (assettask.TaskId == downloadtask.TaskId) { if (assettask.Result.ProgresCallback != null) { int finishcnt; int totalcnt; assettask.IsSubAllDone(ref context, out finishcnt, out totalcnt); ProgressArgs progressArgs = new ProgressArgs((float)finishcnt / totalcnt, 0, assettask.AssetPath, true); assettask.Result.ProgresCallback(ref progressArgs); } break; } } } }
internal static bool InDowloading(ref AssetBundleContext context, ref AssetBundleTask task) { AssetDownloadInfo downloadInfo = new AssetDownloadInfo(); downloadInfo.AssetBundleName = task.AssetBundleName; if (context.DownLoadQueue.Contains(downloadInfo)) { return(true); } if (task.SubTasks != null) { for (int i = 0; i < task.SubTasks.Count; i++) { var subtask = task.SubTasks[i]; if (InDowloading(ref context, ref subtask)) { 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); } } }