/// <summary> /// real load assetbundle /// </summary> /// <param name="req"></param> /// <returns></returns> static protected AssetBundleDownloadOperation LoadAssetBundleInternal(CRequest req) { AssetBundleDownloadOperation abDownloadOp = null; if (!downloadingBundles.TryGetValue(req.key, out abDownloadOp)) { #if HUGULA_PROFILER_DEBUG Profiler.BeginSample(string.Format("LoadAssetBundleInternal ({0},{1},{2})", req.assetName, req.key, req.isShared)); #endif if (!UriGroup.CheckRequestCurrentIndexCrc(req)) //crc { abDownloadOp = new AssetBundleDownloadErrorOperation(); abDownloadOp.error = string.Format("assetbundle({0}) crc check wrong ", req.key); } else if (req.url.StartsWith(Common.HTTP_STRING)) //load assetbunlde { abDownloadOp = AssetBundleDownloadFromWebOperation.Get(); } else { abDownloadOp = AssetBundleDownloadFromDiskOperation.Get(); } abDownloadOp.SetRequest(req); downloadingBundles.Add(req.key, abDownloadOp); CacheData cached = null; CacheManager.CreateOrGetCache(req.keyHashCode, out cached);//cache data //load now if (bundleMax - inProgressBundleOperations.Count > 0) { inProgressBundleOperations.Add(abDownloadOp); abDownloadOp.BeginDownload(); } else { bundleQueue.Enqueue(abDownloadOp); } #if HUGULA_LOADER_DEBUG HugulaDebug.FilterLogFormat(req.key, "<color=#10f010>1.2 LoadAssetBundleInternal Request(key={0},isShared={1},assetname={2},dependencies.count={4})keyHashCode{3}, frameCount{5}</color>", req.key, req.isShared, req.assetName, req.keyHashCode, req.dependencies == null ? 0 : req.dependencies.Length, Time.frameCount); #endif #if HUGULA_PROFILER_DEBUG Profiler.EndSample(); #endif } else if (req.isShared) { req.ReleaseToPool(); } return(abDownloadOp); }
/// <summary> /// append request to queue. /// </summary> /// <param name="req">Req.</param> /// <param name="group">Group.</param> protected static bool AddReqToQueue(CRequest req, GroupRequestRecord group = null) { if (req == null) { return(false); } string key = req.udKey; //the udkey never change 第一个URI和relativeUrl评级而成。 UriGroup.CheckRequestUrlIsAssetbundle(req); if (!req.isShared && group != null) { PushGroup(req, group); } if (CheckLoadAssetAsync(req)) //已经下载 { return(false); #if UNITY_EDITOR } else if (SimulateAssetBundleInEditor && req.isAssetBundle) // { CallbackError(req); return(false); #endif } else if (!UriGroup.CheckRequestCurrentIndexCrc(req)) //如果校验失败 { #if HUGULA_LOADER_DEBUG Debug.LogFormat(" 0.0 <color=#ff0000>CheckCrcUri0Exists==false Req(assetname={0},url={1}) </color>", req.assetName, req.url); #endif CallbackError(req); return(false); } List <CRequest> list = null; if (requestCallBackList.TryGetValue(key, out list)) //.ContainsKey(key)) //回调列表 { #if HUGULA_LOADER_DEBUG Debug.LogFormat(" 0.1 <color=#15A0A1>requestCallBackList.ContainsKey Req(assetname={0},url={1}) </color>", req.assetName, req.url); #endif list.Add(req); return(true); } else { var listreqs = ListPool <CRequest> .Get(); requestCallBackList.Add(key, listreqs); listreqs.Add(req); if (queue.Count == 0 && currentLoading == 0 && loadingAssetBundleQueue.Count == 0) { totalLoading = 0; currentLoaded = 0; } #if HUGULA_LOADER_DEBUG Debug.LogFormat(" 0.1 <color=#15A0A1>LoadAssetBundle Req(assetname={0},url={1} isShared={2},isNormal={3}) </color>", req.assetName, req.url, req.isShared, req.isNormal); #endif if (req.isShared) { QueueOrLoad(req); // LoadAssetBundle(req);// QueueOrLoad (req);//realyLoadingQueue.Enqueue (req); } else if (!req.isNormal) { LoadAssetBundle(req); } else { queue.Push(req); totalLoading++; } return(true); } }
protected static bool AddReqToQueue(CRequest req, GroupRequestRecord group = null) { if (req == null) { return(false); } string key = req.udKey;//the udkey never change 第一个URI和relativeUrl评级而成。 UriGroup.CheckRequestUrlIsAssetbundle(req); if (!UriGroup.CheckRequestCurrentIndexCrc(req)) //如果校验失败 { #if HUGULA_LOADER_DEBUG Debug.LogFormat(" 0. <color=yellow>CheckCrcUri0Exists==false Req(assetname={0},url={1}) </color>", req.assetName, req.url); #endif CallbackError(req); return(false); } if (CheckLoadAssetAsync(req)) //已经下载 { return(false); } else if (requestCallBackList.ContainsKey(key)) //回调列表 { requestCallBackList[key].Add(req); if (!req.isShared) { if (group != null) { PushGroup(req, group); } } return(true); } else { var listreqs = ListPool <CRequest> .Get(); //new List<CRequest>(); requestCallBackList.Add(key, listreqs); listreqs.Add(req); if (queue.Count == 0 && currentLoading == 0 && loadingAssetBundleQueue.Count == 0) { totalLoading = 0; currentLoaded = 0; } if (req.isShared) { QueueOrLoad(req); //realyLoadingQueue.Enqueue (req); } else if (!req.isNormal) { LoadAssetBundle(req); if (group != null) { PushGroup(req, group); } } else { queue.Push(req); totalLoading++; if (group != null) { PushGroup(req, group); } } return(true); } }