/// <summary> /// 递归加载 /// </summary> /// <param name="path"></param> /// <param name="sucessCallback"></param> /// <returns></returns> IEnumerator IELoadAssetBundles(Queue <string> resQue, Action <bool> callback) { string path; if (resQue.Count <= 0) { callback(true); yield break; } else { path = resQue.Dequeue(); } Debug.Log("加载依赖:" + path); WWW www = new WWW(path); yield return(www); if (www.error == null) { if (www.isDone) { UseAssetBunle(path, www.assetBundle); //递归刷出 MainThreadCallTools.StartCoroutine(IELoadAssetBundles(resQue, callback)); yield break; } } else { Debug.LogError("加载失败:" + path); } }
Task now;//当前任务 void DoNext() { if (httpTask.Count > 0) { now = httpTask.Dequeue(); MainThreadCallTools.StartCoroutine(DoTask(now)); } }
public string LoadAsync <T>(string objName, Action <bool, T> action, bool isCreateTaskid = true) where T : UnityEngine.Object { //创建任务序列 string taskid = null; if (isCreateTaskid) { taskid = CreateTaskHash(); mTaskHashTable.Add(taskid); } AsyncTask task = new AsyncTask(); task.id = taskid; task.ResTask(() => { if (objMaps.ContainsKey(objName)) { //判断任务结束 task.EndTask(); //有创建taskid的,判断段taskid是否存在 if (isCreateTaskid == true && mTaskHashTable.Contains(taskid) == false) { Debug.Log("没发现任务id,不执行回调"); return; } action(true, objMaps[objName] as T); } else { MainThreadCallTools.StartCoroutine(IELoadAsync <T>(objName, (bool b, T t) => { //判断任务结束 task.EndTask(); //有创建taskid的,判断段taskid是否存在 if (isCreateTaskid == true && mTaskHashTable.Contains(taskid) == false) { Debug.Log("没发现任务id,不执行回调"); return; } action(b, t); })); } }); mAsyncTaskList.Add(task); return(taskid); }
public void LoadManifestAsync(string path, Action <bool> callback) { //如果存在 不让加载 //if (manifest != null) //{ // callback(true); // return; //} path = Path.Combine(mLocalHotUpdateResPath, path); #if UNITY_EDITOR || UNITY_IPHONE path = "File:///" + path; #endif path = path.Replace("\\", "/"); MainThreadCallTools.StartCoroutine(IELoadAssetBundles(path, callback, true)); }
/// <summary> /// 加载ab /// </summary> /// <param name="path"></param> /// <param name="sucessCallback"></param> public void LoadAssetBundleAsync(string path, Action <bool> sucessCallback) { path = Path.Combine(mLocalHotUpdateResPath, path); #if UNITY_EDITOR || UNITY_IPHONE path = "file:///" + path; #endif path = path.Replace("\\", "/"); if (manifest.Manifest == null) { Debug.LogError("请先加载依赖文件!"); return; } var res = manifest.Manifest.GetDirectDependencies(Path.GetFileName(path)); //创建一个队列 Queue <string> resQue = new Queue <string>(); foreach (var r in res) { string _path = Path.GetDirectoryName(path) + "/" + Path.GetFileName(r); _path = _path.Replace("\\", "/"); var key = Path.GetFileName(_path); if (assetbundleMap.ContainsKey(key) == false) { resQue.Enqueue(_path); } else { assetbundleMap[key].Use(); } } if (assetbundleMap.ContainsKey(Path.GetFileName(path)) == false) { resQue.Enqueue(path); } //开始加载队列 MainThreadCallTools.StartCoroutine(IELoadAssetBundles(resQue, sucessCallback)); }
void OnTimeOut(Task task) { Debug.Log("当前网络不稳定,是否继续?"); MainThreadCallTools.StartCoroutine(DoTask(task)); }