/// <summary> /// 获取Loader /// </summary> /// <param name="hash"></param> /// <returns></returns> public static ABLoader GetLoader(uint hash, ABLoadContext _loadContext) { //如果已经存在Laoder则返回loader if (_loadContext.loadingLoaderDict.ContainsKey(hash)) { return(_loadContext.loadingLoaderDict[hash]); } ABData data = _loadContext.dataHelper.GetABData(hash); if (data == null) { ReDebug.LogError(ReLogType.System, "ABManager", string.Format("ABData is null, abName={0}", hash)); return(null); } //创建Loader并且加入表中 ABLoader loader = ReusableObjectPool <ABLoader> .Get(); loader.abName = data.fullName; loader.abData = data; _loadContext.loadingLoaderDict[hash] = loader; loader._loadContext = _loadContext; return(loader); }
/// <summary> /// 同步加载Bundle /// </summary> /// <param name="hash"></param> /// <param name="location"></param> /// <param name="suffix"></param> /// <returns></returns> public ABObject LoadSync(uint hash, string location, string suffix) { //从缓存中寻找 ABObject abObject = _loadContext.FindABObjectCache(hash); if (abObject != null) { return(abObject); } var loader = ABLoader.GetLoader(hash, _loadContext); #region 异常情况处理 if (loader == null) { ReDebug.LogError(ReLogType.System, "ABManager", string.Format("Cannot create ABLoader, location={0}{1}, name={2}", location, suffix, hash)); return(null); } //如果已经加载完成 if (loader.isComplete) { ReDebug.LogError(ReLogType.System, "ABManager", String.Format("Cannot be here, name={0}", hash)); return(loader.abObject); } #endregion 异常情况处理 loader.Load(true); return(loader.abObject); }
/// <summary> /// 加载等待队列中的Loader /// </summary> public void LoadWaitingLoader() { while (_loadContext.waitingLoaderQueue.Count > 0 && _loadContext.loadingCount < _loadContext.LOADING_LIMIT) { ABLoader loader = _loadContext.waitingLoaderQueue.Dequeue(); loader.LoadBundle(false); _loadContext.loadingCount++; } }
private void LoadDepends(bool immediately, Action <bool> loadSelf) { if (depLoaderList == null) { depLoaderList = ListPool <ABLoader> .Get(); depObjectList = ListPool <ABObject> .Get(); for (int i = 0; i < abData.dependencies.Length; i++) { uint hash = abData.dependencies[i]; ABObject abObject = _loadContext.FindABObjectCache(hash); if (abObject != null) { abObject.ResetLifeTime(); depObjectList.Add(abObject); } else { ABLoader loader = GetLoader(hash, _loadContext); depLoaderList.Add(loader); } } } ABLoader depLoader; int loadDepCount = loadingDepCount = depLoaderList.Count; if (loadDepCount == 0) { loadSelf(immediately); } else { for (int i = 0; i < loadDepCount; i++) { depLoader = depLoaderList[i]; if (depLoader.isComplete) { continue; } depLoader.Load(immediately, (abObject) => { loadingDepCount--; if (loadingDepCount == 0 && state != ABLoadState.LoadingDep) { loadSelf(immediately); } }); } } }
/// <summary> /// 异步加载Bundle /// </summary> /// <param name="hash"></param> /// <param name="location"></param> /// <param name="suffix"></param> /// <param name="callBack"></param> public void LoadAsync(uint hash, string location, string suffix, Action <ABObject> callBack = null) { //从缓存中寻找 ABObject abObject = _loadContext.FindABObjectCache(hash); if (abObject != null) { if (callBack != null) { callBack(abObject); } return; } var loader = ABLoader.GetLoader(hash, _loadContext); #region 异常情况处理 if (loader == null) { ReDebug.LogError(ReLogType.System, "ABManager", string.Format("Cannot create ABLoader, location={0}{1}, name={2}", location, suffix, hash)); if (callBack != null) { callBack(null); } return; } //如果已经加载完成 if (loader.isComplete) { ReDebug.LogError(ReLogType.System, "ABManager", String.Format("Cannot be here, name={0}", hash)); if (callBack != null) { callBack(loader.abObject); } return; } #endregion 异常情况处理 loader.Load(false, callBack); }