static private GetCache ( int assethashcode ) : |
||
assethashcode | int | |
return |
/// <summary> /// 目标引用减一 /// </summary> /// <param name="hashcode"></param> /// <returns></returns> internal static bool Subtract(int hashcode) { CacheData cached = CacheManager.GetCache(hashcode); if (cached != null) { cached.count--; // = cached.count - 1; if (cached.count <= 0) //所有引用被清理。 { CacheManager.ClearCache(hashcode); } return(true); } return(false); }
static protected bool LoadAssetBundleInternal(CRequest req) { if (!downloadingBundles.Contains(req.key) && CacheManager.GetCache(req.keyHashCode) == null) { if (bundleMax - downloadingBundles.Count > 0) { var op = OperationPools <LoadAssetBundleInternalOperation> .Get(); op.SetRequest(req); inProgressOperations.Add(op); op.Start(); downloadingBundles.Add(req.key); return(true); } else { inProgressBundleOperations.Add(req); //wait bundle } } return(false); }
/// <summary> /// load assetbundle /// </summary> /// <param name="req"></param> static internal void LoadAssetFromBundle(CRequest req) { #if UNITY_EDITOR if (ManifestManager.SimulateAssetBundleInEditor) { LoadAssetInternalSimulation(req); return; } #endif totalCount++; //count ++ if (CheckAssetIsLoaded(req)) { return; } //remove delay unload assetbundle ABDelayUnloadManager.CheckRemove(req.keyHashCode); loadingTasks.Add(req); //loading assetbundle if (!downloadingBundles.Contains(req.key) && CacheManager.GetCache(req.keyHashCode) == null) //check is loading { //load dependencies and refrenece count string[] deps = null; if (ManifestManager.fileManifest != null && (deps = ManifestManager.fileManifest.GetDirectDependencies(req.key)).Length > 0) { req.dependencies = LoadDependencies(req, deps); } //load assetbundle LoadAssetBundleInternal(req); } LoadAssetInternal(req); }
/// <summary> /// 加载依赖项目 /// </summary> /// <param name="req"></param> static protected int[] LoadDependencies(CRequest req) { string[] deps = assetBundleManifest.GetDirectDependencies(req.assetBundleName); if (deps.Length == 0) { return(null); } string dep_url; string depAbName = ""; CRequest item; int[] hashs = new int[deps.Length]; int keyhash; for (int i = 0; i < deps.Length; i++) { depAbName = deps[i]; if (string.IsNullOrEmpty(depAbName)) // Dependency assetbundle name is empty unity bug? { #if UNITY_EDITOR Debug.LogWarningFormat("the request({0},{1}) Dependencies {2} is empty ", req.assetName, req.url, i); #endif hashs[i] = 0; continue; } dep_url = RemapVariantName(depAbName); keyhash = LuaHelper.StringToHash(dep_url); hashs[i] = keyhash; #if UNITY_EDITOR CountMananger.WillAdd(dep_url); //引用数量加1 #else CountMananger.WillAdd(keyhash); //引用数量加1 #endif CacheData sharedCD = CacheManager.GetCache(keyhash); if (sharedCD != null) { if (!sharedCD.isAssetLoaded) { item = LRequest.Get(); item.relativeUrl = dep_url; item.isShared = true; item.async = false; item.isAssetBundle = true; CacheManager.SetRequestDataFromCache(req); if (_instance && _instance.OnSharedComplete != null) { _instance.OnSharedComplete(item); } LRequest.Release(item); } #if HUGULA_LOADER_DEBUG Debug.LogFormat(" 0.3 <color=#15A0A1>Request(assetName={0}, url={1},isShared={2}) Dependencies CacheManager.Contains(url={3},sharedCD.isAssetLoaded={4}) </color>", req.assetName, req.url, req.isShared, dep_url, sharedCD.isAssetLoaded); #endif } else { item = LRequest.Get(); item.relativeUrl = dep_url; item.isShared = true; item.async = false; item.isAssetBundle = true; item.allDependencies = LoadDependencies(item); item.isNormal = false; item.priority = req.priority; item.uris = req.uris; #if HUGULA_LOADER_DEBUG Debug.LogFormat("<color=#15A0A1>0.5 Request(assetname={0}) Begin Load Dependencies Req({1},allDependencies.count={3})keyHashCode{2}, frameCount{4}</color>", req.assetName, item.assetName, item.keyHashCode, item.allDependencies == null ? 0 : item.allDependencies.Length, Time.frameCount); #endif AddReqToQueue(item); } } return(hashs); }