/// <summary> /// 已经存在资源,或者加载失败后操作 /// </summary> /// <param name="id"></param> /// <param name="stPath"></param> private void LoaderOperater(string id, StResPath stPath) { ResLoaderOrder resLoaderOrder = this.GetWwwLoaderOrderByOrderName(id); if (resLoaderOrder == null) { return; } //刷新队列加载情况 resLoaderOrder.UpdateLoaderOrderState(stPath); //更新当前队列进度 UpdateListProgressHanler(resLoaderOrder); //触发单个文件完成 resLoaderOrder.InvokeLoaderFileComplete(stPath.path); //如果队列完成通知结束 if (resLoaderOrder.IsFinished()) { this._orderList.Remove(resLoaderOrder); resLoaderOrder.InvokeLoaderListComplete(); resLoaderOrder.Dispose(); resLoaderOrder = null; } //next LoadThreadManager.instance.CheckQueue(); }
/// <summary> /// 本地加载,支持 texture,audio,txt,types,prefab /// </summary> /// <param name="resPath">路径需包含后缀名,本地载入会进行截取</param> /// <param name="loaderFileComplete"></param> /// <param name="loaderError"></param> /// <param name="param"></param> private static void LoadFromLocalRes <T>( StResPath resPath, string id, ResLoaderManager.DelegateListLoaded loaderListComplete, ResLoaderManager.DelegateFileLoaded loaderFileComplete, ResLoaderManager.DelegateLoaderError loaderError, ResLoaderManager.DelageteLoaderListProgress loaderListProgress = null, object param = null) where T : UnityEngine.Object { //完整路径 string fullPath = SystemConfig.localPlatformResPath + resPath.path + ".unity3d"; if (ResDataManager.instance.HasEditorRes(fullPath)) { if (loaderFileComplete != null) { loaderFileComplete(fullPath, param); } } else { VOLocalLoadNode node = new VOLocalLoadNode(); node.resPath = resPath; node.id = id; node.loaderListComplete = loaderListComplete; node.loaderFileComplete = loaderFileComplete; node.loaderError = loaderError; node.loaderListProgress = loaderListProgress; node.param = param; node.type = typeof(T).ToString(); StartLoad(node); } }
/// <summary> /// 更新队列的加载情况 /// </summary> /// <param name="stPath"></param> /// <returns></returns> public bool UpdateLoaderOrderState(StResPath stPath) { if (this.pathList.Contains(stPath)) { this.currLoadedNum++; return(true); } return(false); }
/// <summary> /// 加载 /// </summary> /// <param name="stPath"></param> /// <param name="loaderProgress"></param> /// <param name="loaderComplete"></param> /// <param name="loaderError"></param> public void Loader(StResPath stPath, ResLoader.DelegateResLoaderProgress loaderProgress, ResLoader.DelegateResLoaderComplete loaderComplete, ResLoader.DelegateResLoaderError loaderError) { this._loaderProgress += loaderProgress; this._loaderComplete += loaderComplete; this._loaderError += loaderError; this.stResPath = stPath; //添加到加载队列 LoadThreadManager.instance.AddNode(this); }
public void UnLoad(bool unLoadUseObj = false) { for (int i = 0; i < _resList.Count; i++) { StResPath resPath = _resList[i]; ResDataManager.instance.RemoveAssetBundle(resPath.path, true, unLoadUseObj); } _resList.Clear(); _resList = null; _callback = null; }
/// <summary> /// 单个资源加载 /// </summary> /// <param name="resPath"></param> /// <param name="loaderComplete"></param> /// <param name="loaderProgress"></param> /// <param name="loaderError"></param> /// <param name="param"></param> public void Loader( StResPath resPath, ResLoaderManager.DelegateFileLoaded loaderFileComplete, ResLoaderManager.DelegateLoaderProgress loaderProgress = null, ResLoaderManager.DelegateLoaderError loaderError = null, object param = null) { List <StResPath> pathList = new List <StResPath>(); pathList.Add(resPath); Loader(pathList, resPath.path, null, loaderProgress, loaderError, null, loaderFileComplete, param); }
private void OnSoundLoaded(string filePath, object param = null) { StResPath stPath = (StResPath)param; string fileName = stPath.GetFileName(); //获取audio,并释放ab文件 AudioClip clip = ResDataManager.instance.CreateObjectFromCache <AudioClip>(filePath, true); if (clip != null) { SoundResLib.AddAudioClip(fileName, clip, stPath.tag); this.play(clip, this.getFreeAudioSource()); } }
/// <summary> /// 单个文件加载 /// </summary> /// <param name="resPath"></param> /// <param name="loaderFileComplete"></param> /// <param name="loaderProgress"></param> /// <param name="loaderError"></param> /// <param name="param"></param> public static void Load <T>( StResPath resPath, ResLoaderManager.DelegateFileLoaded loaderFileComplete, ResLoaderManager.DelegateLoaderProgress loaderProgress = null, ResLoaderManager.DelegateLoaderError loaderError = null, object param = null) where T : UnityEngine.Object { resPath.path = FormatLocalPath(resPath.path); if (!isByWWWLoad) { LoadFromLocalRes <T>(resPath, resPath.path, null, loaderFileComplete, loaderError, null, param); } else { resPath.path = SystemConfig.localPlatformResPath + resPath.path + ".unity3d"; ResLoaderManager.instance.Loader(resPath, loaderFileComplete, loaderProgress, loaderError, param); } }
private void LoadSoundAssetBundle(string path, ResTag tag) { StResPath stPath = new StResPath(path, tag); ResLoadTool.Load <AudioClip>(stPath, OnSoundLoaded, null, OnSoundLoadError, stPath); }
public void AddList(StResPath path) { _resList.Add(path); IsLoaded = false; }
/// <summary> /// 队列加载 /// </summary> /// <param name="pathList"></param> /// <param name="id"></param> /// <param name="loaderListComplete">队列加载完成</param> /// <param name="loaderProgress">单个文件进度</param> /// <param name="loaderError">单个文件错误</param> /// <param name="loaderListProgress">队列进度</param> /// <param name="loaderFileComplete">单个加载完成</param> /// <param name="param"></param> public void Loader( List <StResPath> pathList, string id, ResLoaderManager.DelegateListLoaded loaderListComplete, ResLoaderManager.DelegateLoaderProgress loaderProgress = null, ResLoaderManager.DelegateLoaderError loaderError = null, ResLoaderManager.DelageteLoaderListProgress loaderListProgress = null, ResLoaderManager.DelegateFileLoaded loaderFileComplete = null, object param = null) { if (this._orderList == null) { this._orderList = new List <ResLoaderOrder>(); } //去重处理 ResLoaderOrder resLoaderOrder = this.GetWwwLoaderOrderByOrderName(id); if (resLoaderOrder != null) { if (LoadThreadManager.showDebug) { Log.info("[Warn! 与当前加载中的list名相同,请确保唯一性!] id: " + id); } //如果已有相同的资源在加载,添加新回调 resLoaderOrder.AttachEvent(loaderListComplete, loaderProgress, loaderError, loaderListProgress, loaderFileComplete); return; } //添加到订阅队列中 IList <StResPath> pList = new List <StResPath>(pathList.ToArray()); resLoaderOrder = new ResLoaderOrder(id, pList, loaderProgress, loaderListComplete, loaderError, loaderListProgress, loaderFileComplete, param); this._orderList.Add(resLoaderOrder); //遍历订阅文件,开始推入线程加载 int len = resLoaderOrder.pathList.Count; if (len == 0) { this.LoaderOperater(id); return; } for (int i = 0; i < len; i++) { StResPath stPath = resLoaderOrder.pathList[i]; //检查是否在缓存对象中,是否已经加载过 bool existsStatus = ResDataManager.instance.ExistWWWData(stPath.path); if (!existsStatus) {//不存在,加载并缓存 ResLoader resLoader = new ResLoader(resLoaderOrder.Id); resLoader.Loader(stPath, OnProgressHandler, OnCompleteHandler, OnErrorHandler); } else {//资源已存在,无需加载 if (LoadThreadManager.showDebug) { Log.info("加载 " + stPath.path + " 资源已存在 !"); } this.LoaderOperater(id, stPath); } } }