/// <summary> /// 创建场景加载任务 /// </summary> /// <param name="strAssetPath">资源相对于Resources的路径</param> public SceneAssetBundleLoadTask(string strSceneName, string strPath, int version, bool bAdditive, bool isAutoStart = true) : base(false)//SceneAssetBundleLoadTask是不参与下载的,所以用false { string exr_path = "resources/levels/" + strSceneName + "/lightmap_comp_light.exr"; _taskName = "resources/levels/" + strSceneName + "/" + strSceneName + ".unity3d"; _sSceneName = strSceneName; _strPath = strPath; _iVersion = version; _bAdditive = bAdditive; _bDownLoading = true; // AssetBundleLoadTaskItem load_task_exr = new AssetBundleLoadTaskItem(exr_path); // load_task_exr.EventFinished += LoadFinishedHandler; // _listTaskItem.Add(load_task_exr); if (string.IsNullOrEmpty(strPath)) { AssetBundleLoadTaskItem load_task = new AssetBundleLoadTaskItem(_taskName); load_task.EventFinished += LoadFinishedHandler; _listTaskItem.Add(load_task); } else { SceneHttpLoadTask load_task = new SceneHttpLoadTask(strSceneName, strPath, version, isAutoStart); load_task.EventFinished += LoadFinishedHandler; _listTaskItem.Add(load_task); } // string[] objDepRec = AssetManager.getInstance().getAssetBundleDependencies(_taskName); // if (objDepRec != null) // { // for (int i = 0; i < objDepRec.Length; i++) // { // AssetBundleLoadTaskItem load_task = new AssetBundleLoadTaskItem(objDepRec[i]); // load_task.EventFinished += LoadFinishedHandler; // _listTaskItem.Add(load_task); // } // } CollectAllDependFiles(_taskName); _listAssetsPathDepend.Remove(_taskName); for (int i = 0; i < _listAssetsPathDepend.Count; i++) { AssetBundleLoadTaskItem load_task = new AssetBundleLoadTaskItem(_listAssetsPathDepend[i]); load_task.EventFinished += LoadFinishedHandler; _listTaskItem.Add(load_task); } }
public bool GetLoadingAssetPathTask(out AssetBundleLoadTaskItem taskLoading, string sAssetPath) { if (sAssetPath.Length == 0) { taskLoading = null; return(false); } //先从任务列表中找 for (int i = 0; i < _listTaskItem.Count; i++) { if (_listTaskItem[i]._taskName == sAssetPath) { taskLoading = _listTaskItem[i] as AssetBundleLoadTaskItem; return(true); } } taskLoading = null; return(false); }
public void OtherTaskLoadingAssetPath(out AssetBundleLoadTaskItem taskLoading, string assetBundlePath) { taskLoading = null; int count = _listRuningTasks.Count; bool bLoading = false; bool bWaiting = false; for (int i = 0; i < count; i++) { AssetBundleLoadTaskItem loadtask = _listRuningTasks[i] as AssetBundleLoadTaskItem; if (loadtask != null) { if (loadtask._taskName == assetBundlePath) { //taskLoading = loadtask; if (loadtask.IsLoadComplete())//优先取已加载完的 { taskLoading = loadtask; return; } else if (bLoading) { continue; } else if (!bLoading && loadtask.IsLoading())//其次取正在加载的 { taskLoading = loadtask; bLoading = true; } else if (bWaiting) { continue; } else if (!bWaiting && loadtask.IsWaiting())//最次取正在等待的 { taskLoading = loadtask; bWaiting = true; } } } } }
/// <summary> /// 创建资源加载任务 /// </summary> /// <param name="strAssetPath">资源相对于Resources的路径</param> public AssetBundleLoadTask(string strAssetPath, string[] append = null, bool isAutoStart = true) : base(false)//AssetBundleLoadTask是不参与下载的,所以用false { _taskName = strAssetPath; strAssetPath = strAssetPath.ToLower(); _strTaskName = strAssetPath;// GetNameFromPath(strAssetPath); // string[] objDepRec = AssetManager.getInstance().getAssetBundleDependencies(strAssetPath); // if (objDepRec != null) // { // for (int i = 0; i < objDepRec.Length; i++ ) // { // if (objDepRec[i] != strAssetPath) // _listAssetsPathWaitingLoad.Add(objDepRec[i]); // } // // if (append != null) // { // for (int i = 0; i < append.Length; i++) // { // if (!_listAssetsPathWaitingLoad.Contains(append[i].ToLower())) // _listAssetsPathWaitingLoad.Add(append[i].ToLower()); // } // } // _listAssetsPathWaitingLoad.Add(strAssetPath); // } // else // { // _listAssetsPathWaitingLoad.Add(strAssetPath); // } CollectAllDependFiles(strAssetPath, append); for (int i = 0; i < _listAssetsPathWaitingLoad.Count; i++) { AssetBundleLoadTaskItem loadtask = new AssetBundleLoadTaskItem(_listAssetsPathWaitingLoad[i], isAutoStart); loadtask.EventFinished += FinishedHandlerCallback; _listTaskItem.Add(loadtask); } }