/// <summary> /// 加载assetbundle /// </summary> /// <param name="string">assetBundleName</param> /// <param name="bool">async = true 异步加载</param> /// <returns></returns> static void LoadDependencies(string assetBundleName, string[] deps, bool async) { string item = null; if (deps.Length > 0) { // Debug.LogFormat("LoadDependencies assetBundleName={0},deps={0},len={1}", assetBundleName, string.Concat(deps), deps.Length); CacheManager.AddDependencies(assetBundleName, deps); //记录引用关系 //开始加载依赖 for (int i = 0; i < deps.Length; i++) { item = deps[i]; if (!item.Equals(assetBundleName)) { CacheData cacheData = null; CacheManager.CreateOrGetCache(item, out cacheData); cacheData.count++; //引用计数加1 ABDelayUnloadManager.Remove(item); //从列表移除 if (!cacheData.canUse) { LoadAssetBundleInternal(item, async); } } } } }
/// <summary> /// 加载assetbundle /// </summary> /// <param name="assetBundleName"> string 加载资源名</param> /// <param name="async"> bool 异步加载默认ture</param> /// <returns></returns> internal static bool LoadAssetBundle(string assetBundleName, bool async = true) { #if UNITY_EDITOR if (SimulateAssetBundleInEditor) { return(false); } #endif //查找缓存 CacheData cacheData = null; CacheManager.CreateOrGetCache(assetBundleName, out cacheData); cacheData.count++; //引用计数加1 ABDelayUnloadManager.Remove(assetBundleName); //从回收列表移除 if (cacheData.canUse) { return(true); } //开始加载依赖 string[] deps = null; if (ManifestManager.fileManifest != null && (deps = ManifestManager.fileManifest.GetDirectDependencies(assetBundleName)).Length > 0) { LoadDependencies(assetBundleName, deps, async); } //加载assetbundle LoadAssetBundleInternal(assetBundleName, async); return(false); }
/// <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)) { req.url = GetAssetBundleDownloadingURL(req.vUrl); // set full url 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 inProgressBundleOperations.Add(abDownloadOp); abDownloadOp.BeginDownload(); #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 } else if (req.isShared) { req.ReleaseToPool(); } return(abDownloadOp); }
internal static int WillAdd(string key) { CacheData cached = null; CacheManager.CreateOrGetCache(key, out cached); cached.count++; return(cached.count); }
public static int WillAdd(string key) { CacheData cached = null; CacheManager.CreateOrGetCache(key, out cached); cached.count++; #if HUGULA_CACHE_DEBUG UnityEngine.Debug.LogFormat(" <color=#fcfcfc> will add (assetBundle={0},hash={1},count={2}) frameCount{3}</color>", cached.assetBundleKey, cached.assetHashCode, cached.count, UnityEngine.Time.frameCount); #endif return(cached.count); }
internal static int WillAdd(int hashcode) { #if UNITY_EDITOR if (ManifestManager.SimulateAssetBundleInEditor) { return(1); } #endif CacheData cached = null; CacheManager.CreateOrGetCache(hashcode, out cached); cached.count++; return(cached.count); }
/// <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); }
public static int WillAdd(int hashcode) { #if UNITY_EDITOR if (CResLoader.SimulateAssetBundleInEditor) { return(1); } #endif CacheData cached = null; CacheManager.CreateOrGetCache(hashcode, out cached); cached.count++; #if HUGULA_CACHE_DEBUG UnityEngine.Debug.LogFormat(" <color=#fcfcfc> will add (assetBundle={0},,hash={1},count={2}) frameCount{3}</color>", cached.assetBundleKey, cached.assetHashCode, cached.count, UnityEngine.Time.frameCount); #endif return(cached.count); }