/// <summary> /// 添加一个资源包加载任务 /// </summary> protected void ScheduleTask(AsyncLoadingTask task) { AbstractAssetBundleRef abRef; if (TryGetAssetBundle(task.assetbundleName, out abRef)) { abRef.lastLoaded = Time.realtimeSinceStartup; Log("Loaded: {0}", task); if (task.onABLoaded != null) { task.onABLoaded.Invoke(abRef, null); } if (task.onObjectLoaded != null) { task.onObjectLoaded.Invoke(abRef.Load(task.assetName, task.type), task.param); } } else { Log("Enqueue: {0}", task); m_Tasks.Enqueue(task); if (m_CurrentTask == null) { StartCoroutine(LoadAssetBundleOnebyone()); } } }
protected override IEnumerator PerformTask(AsyncLoadingTask task, ABRefOut output) { yield return(null); SimAssetBundle abRef; if (m_AllAssetBundles.TryGetValue(task.assetbundleName, out abRef)) { abRef.loaded = true; abRef.SetAllowUnload(task.allowUnload); output.abRef = abRef; output.md5 = ""; } }
/// <summary> /// 资源从磁盘载入 /// </summary> protected abstract IEnumerator PerformTask(AsyncLoadingTask task, ABRefOut output);
protected override IEnumerator PerformTask(AsyncLoadingTask task, ABRefOut output) { string suitPath = ""; string abName = task.assetbundleName; if (!task.forcedStreaming) { suitPath = Path.Combine(bundleRootPath, abName); } if (!File.Exists(suitPath)) { suitPath = Path.Combine(streamingRootPath, abName); } if (!suitPath.Contains("://")) { if (suitPath.Contains(":")) { suitPath = "file:///" + suitPath; } else { suitPath = "file://" + suitPath; } } WWW www = new WWW(suitPath); yield return(www); if (www.error == null) { // 把资源缓存到persistentDataPath output.transfer = new AssetsTransfer(www.bytes, Path.Combine(bundleRootPath, abName)); if (task.needMD5) { output.md5 = CMD5.MD5Data(www.bytes); } AssetBundle ab = www.assetBundle; if (ab != null) { //// 资源是一个AssetBundle,获取Bundle里的所有Assets, 保存 //AssetBundleRequest abReq = ab.LoadAllAssetsAsync(); //while (!abReq.isDone) { // if (progressView && progressView.gameObject.activeInHierarchy) { // progressView.value = abReq.progress; // } // yield return 1; //} //if (progressView && progressView.gameObject.activeInHierarchy) { // progressView.value = 1; //} if (output.abRef == null) { output.abRef = new AssetBundleRef(abName, ab, task.allowUnload); } else { var abRef = output.abRef as AssetBundleRef; abRef.Init(abName, ab, task.allowUnload); } } } }