Esempio n. 1
0
 public override void Enqueue(CRequest req)
 {
     if (ResourcesLoader.LoadAssetFromCache(req))
     {
         ABDelayUnloadManager.CheckRemove(req.keyHashCode);
         ResourcesLoader.DispatchReqAssetOperation(req, false);
     }
     else
     {
         req.group = this;
         base.Enqueue(req);
     }
 }
Esempio n. 2
0
 static protected bool CheckAssetIsLoaded(CRequest req)
 {
     if (LoadAssetFromCache(req))
     {
         ABDelayUnloadManager.CheckRemove(req.keyHashCode);
         DispatchReqAssetOperation(req, false);
         return(true);
     }
     else
     {
         return(false);
     }
 }
Esempio n. 3
0
        /// <summary>
        /// check load from cache
        /// </summary>
        /// <param name="req"></param>
        static bool CheckLoadAssetAsync(CRequest req)
        {
#if UNITY_EDITOR
            if (SimulateAssetBundleInEditor && CacheManager.SetRequestDataFromPrefab(req))
            {
                loadingAssetQueue.Add(req);
                return(true);
            }
#endif

            ABDelayUnloadManager.CheckRemove(req.keyHashCode);
            if (CacheManager.Contains(req.keyHashCode))
            {
                AddReqToAssetCallBackList(req);
                return(true);
            }
            return(false);
        }
Esempio n. 4
0
        /// <summary>
        /// 目标引用加一
        /// </summary>
        /// <param name="hashcode"></param>
        /// <returns></returns>
        public static int Add(int hashcode)
        {
#if UNITY_EDITOR
            if (CResLoader.SimulateAssetBundleInEditor)
            {
                return(1);
            }
#endif
            CacheData cached = CacheManager.TryGetCache(hashcode);
            if (cached != null)
            {
                ABDelayUnloadManager.CheckRemove(hashcode);
                cached.count++; //= cached.count + 1;
#if HUGULA_CACHE_DEBUG
                UnityEngine.Debug.LogFormat(" <color=#0cbcbc>add  (assetBundle={0},count={1})  frameCount{2}</color>", cached.assetBundleKey, cached.count, UnityEngine.Time.frameCount);
#endif
                return(cached.count);
            }
            return(-1);
        }
Esempio n. 5
0
        /// <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);
        }
Esempio n. 6
0
        /// <summary>
        /// check load from cache
        /// </summary>
        /// <param name="req"></param>
        static bool CheckLoadAssetAsync(CRequest req)
        {
            ABDelayUnloadManager.CheckRemove(req.keyHashCode);
            if (CacheManager.SetRequestDataFromCache(req))
            {
                if (req.assetBundleRequest != null)
                {
                    AddReqToAssetCallBackList(req);
#if HUGULA_LOADER_DEBUG
                    Debug.LogFormat("<color=#15C1B2> 1.1 from cache CheckLoadAssetAsync=true Req(assetname={0},url={1})  </color>", req.assetName, req.url);
#endif
                }
                else
                {
#if HUGULA_LOADER_DEBUG
                    Debug.LogFormat("<color=#15C1B2> 1.2 from cache CheckLoadAssetAsync=false Req(assetname={0},url={1})  </color>", req.assetName, req.url);
#endif
                    LoadAssetComplate(req);
                }
                return(true);
            }
            return(false);
        }
Esempio n. 7
0
        /// <summary>
        /// 目标引用加一
        /// </summary>
        /// <param name="hashcode"></param>
        /// <returns></returns>
        public static int Add(int hashcode)
        {
#if UNITY_EDITOR
            if (ManifestManager.SimulateAssetBundleInEditor)
            {
                return(1);
            }
#endif
            CacheData cached = CacheManager.TryGetCache(hashcode);
            if (cached != null)
            {
                cached.count++;        //= cached.count + 1;

                if (cached.count == 1) //last refercount == 0 should check remove list
                {
                    ABDelayUnloadManager.CheckRemove(hashcode);
                }
#if HUGULA_CACHE_DEBUG
                HugulaDebug.FilterLogFormat(cached.assetBundleKey, " <color=#0cbcbc>add  (assetBundle={0},hashcode={1},count={2})  frameCount{3}</color>", cached.assetBundleKey, hashcode, cached.count, UnityEngine.Time.frameCount);
#endif
                return(cached.count);
            }
            return(-1);
        }
Esempio n. 8
0
        /// <summary>
        /// load LoadDependencies assetbundle
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        static protected int[] LoadDependencies(CRequest req, string[] deps)
        {
            // string[] deps = ManifestManager.fileManifest.GetDirectDependencies (req.key);
            if (deps.Length == 0)
            {
                return(null);
            }
            string abName = string.Empty;

            string   dep_url;
            string   depAbName = "";
            CRequest item;

            int[] hashs = new int[deps.Length];
            int   keyhash;

            for (int i = 0; i < deps.Length; i++)
            {
                depAbName = CUtils.GetBaseName(deps[i]);
                dep_url   = ManifestManager.RemapVariantName(depAbName); //string gc alloc

                keyhash  = LuaHelper.StringToHash(dep_url);
                hashs[i] = keyhash;

                CacheData sharedCD = CacheManager.TryGetCache(keyhash);
                if (sharedCD != null)
                {
                    sharedCD.count++;
                    int count = sharedCD.count; //CountMananger.WillAdd(keyhash); //引用数量加1;
#if HUGULA_CACHE_DEBUG
                    HugulaDebug.FilterLogFormat(dep_url, " <color=#fcfcfc> add  (assetBundle={0},parent={1},hash={2},count={3}) frameCount={4}</color>", dep_url, req.key, keyhash, count, UnityEngine.Time.frameCount);
#endif
                    if (count == 1) //相加后为1,可能在回收列表,需要对所有依赖项目引用+1
                    {
                        ABDelayUnloadManager.CheckRemove(keyhash);
                    }
                }
                else
                {
#if HUGULA_CACHE_DEBUG
                    int count = CountMananger.WillAdd(keyhash);  //引用数量加1
                    HugulaDebug.FilterLogFormat(dep_url, " <color=#fcfcfc> will add  (assetBundle={0},parent={1},hash={2},count={3}) frameCount={4}</color>", dep_url, req.key, keyhash, count, UnityEngine.Time.frameCount);
#else
                    CountMananger.WillAdd(keyhash);  //引用数量加1
#endif
                    item          = CRequest.Get();
                    item.vUrl     = dep_url;
                    item.isShared = true;
                    item.async    = req.async;
                    item.priority = req.priority;
                    string[] deps1 = ManifestManager.fileManifest.GetDirectDependencies(item.key);
                    if (deps1.Length > 0)
                    {
                        item.dependencies = LoadDependencies(req, deps1);
                    }
                    LoadAssetBundleInternal(item);
                }
            }

            return(hashs);
        }
Esempio n. 9
0
        /// <summary>
        /// load assetbundle
        /// </summary>
        /// <param name="req"></param>
        static protected void LoadAssetBundle(CRequest req)
        {
#if UNITY_EDITOR
            if (ManifestManager.SimulateAssetBundleInEditor)
            {
                //load asset
                ResourcesLoadOperation operation1;
                var tp1 = req.assetType;

                if (req.assetOperation != null)
                {
                    operation1 = req.assetOperation;
                }
                else if (CacheManager.Typeof_ABScene.Equals(tp1))
                {
                    operation1 = new AssetBundleLoadLevelSimulationOperation();
                    operation1.SetRequest(req);
                }
                else
                {
                    operation1 = new AssetBundleLoadAssetOperationSimulation();
                    operation1.SetRequest(req);
                }

                bool isLoading1 = false;

                if (operation1 is AssetBundleLoadAssetOperation)
                {
                    isLoading1 = AddAssetBundleLoadAssetOperationToCallBackList((AssetBundleLoadAssetOperation)operation1);
                }

                if (!isLoading1)
                {
                    inProgressOperations.Add(operation1);
                    loadingTasks.Add(req);
                }
                return;
            }
#endif
            //remove delay unload assetbundle
            ABDelayUnloadManager.CheckRemove(req.keyHashCode);

            //check load asset from cache
            if (LoadAssetFromCache(req))
            {
                DispatchReqAssetOperation(req, false);
                return;
            }

            totalCount++;//count ++
#if HUGULA_PROFILER_DEBUG
            Profiler.BeginSample(string.Format("LoadAssetBundle ({0},{1},{2}) LoadDependencies and LoadAssetBundleInternal", req.assetName, req.key, req.isShared));
#endif
            AssetBundleDownloadOperation abDownloadOperation = null;

            if (downloadingBundles.TryGetValue(req.key, out abDownloadOperation)) //check is loading
            {
            }
            else if (CheckAssetBundleCanLoad(req)) //need load
            {
                //load dependencies and refrenece count
                if (ManifestManager.fileManifest != null)
                {
                    req.dependencies = LoadDependencies(req); //load dependencies assetbundle
                }
                //load assetbundle
                abDownloadOperation = LoadAssetBundleInternal(req);
            }
#if HUGULA_PROFILER_DEBUG
            Profiler.EndSample();
#endif

#if HUGULA_PROFILER_DEBUG
            Profiler.BeginSample(string.Format("LoadAssetBundle  ({0},{1},{2}) to inProgressOperations", req.assetName, req.key, req.isShared));
#endif
            //load asset
            ResourcesLoadOperation operation;
            var tp = req.assetType;

            if (req.assetOperation != null)
            {
                operation = req.assetOperation;
            }
            else if (CacheManager.Typeof_ABScene.Equals(tp))
            {
                operation = new AssetBundleLoadLevelOperation();
                operation.SetRequest(req);
            }
            else
            {
                operation = AssetBundleLoadAssetOperationFull.Get();
                operation.SetRequest(req);
            }

            bool isLoading = false;
            //the same asset be one Operation
            if (operation is AssetBundleLoadAssetOperation)
            {
                isLoading = AddAssetBundleLoadAssetOperationToCallBackList((AssetBundleLoadAssetOperation)operation);
            }

            if (!isLoading)
            {
                if (abDownloadOperation != null)
                {
                    abDownloadOperation.AddNext(operation);//wait for assetbunle complete
                }
                else
                {
                    inProgressOperations.Add(operation);// the assetbundle is done
                }
                loadingTasks.Add(req);
            }
#if HUGULA_PROFILER_DEBUG
            Profiler.EndSample();
#endif
#if HUGULA_LOADER_DEBUG
            HugulaDebug.FilterLogFormat(req.key, "<color=#15A0A1>2.0 LoadAssetBundle Asset Request(url={0},assetname={1},dependencies.count={3})keyHashCode{2}, frameCount{4}</color>", req.url, req.assetName, req.keyHashCode, req.dependencies == null ? 0 : req.dependencies.Length, Time.frameCount);
#endif
        }
Esempio n. 10
0
        /// <summary>
        /// load LoadDependencies assetbundle
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        static protected int[] LoadDependencies(CRequest req, CRequest parent)
        {
            string[] deps = ManifestManager.fileManifest.GetDirectDependencies(req.assetBundleName);
            if (deps.Length == 0)
            {
                return(null);
            }
            string abName = string.Empty;

            if (parent != null)
            {
                abName = CUtils.GetBaseName(parent.assetBundleName);
            }

#if HUGULA_PROFILER_DEBUG
            Profiler.BeginSample(string.Format("LoadDependencies ({0},{1},{2}) new int[deps.Length]", req.assetName, req.key, req.isShared));
#endif
            string   dep_url;
            string   depAbName = "";
            CRequest item;
            int[]    hashs = new int[deps.Length];
            int      keyhash;
#if HUGULA_PROFILER_DEBUG
            Profiler.EndSample();
#endif

            for (int i = 0; i < deps.Length; i++)
            {
                depAbName = CUtils.GetBaseName(deps[i]);
                if (abName == depAbName)
                {
#if UNITY_EDITOR
                    Debug.LogErrorFormat("Dependencies({1}) Contains the parent({0}) ! ", req.assetBundleName, abName);
#else
                    Debug.LogWarningFormat("Dependencies({1}) Contains the parent({0}) ! ", req.assetBundleName, abName);
#endif
                    hashs[i] = 0;
                    continue;
                }

                dep_url = ManifestManager.RemapVariantName(depAbName);//string gc alloc

                keyhash  = LuaHelper.StringToHash(dep_url);
                hashs[i] = keyhash;

                CacheData sharedCD = CacheManager.TryGetCache(keyhash);
                if (sharedCD != null)
                {
                    sharedCD.count++;
                    int count = sharedCD.count;//CountMananger.WillAdd(keyhash); //引用数量加1;
#if HUGULA_CACHE_DEBUG
                    HugulaDebug.FilterLogFormat(dep_url, " <color=#fcfcfc> add  (assetBundle={0},parent={1},hash={2},count={3}) frameCount={4}</color>", dep_url, req.key, keyhash, count, UnityEngine.Time.frameCount);
#endif
                    if (count == 1)//相加后为1,可能在回收列表,需要对所有依赖项目引用+1
                    {
                        ABDelayUnloadManager.CheckRemove(keyhash);
                    }
#if HUGULA_LOADER_DEBUG
                    HugulaDebug.FilterLogFormat(req.key, " <color=#15A0A1> 1.1 Shared  AssetBundle is Done Request(assetName={0})  Parent Req(assetName={1},key={2},isShared={3}) </color>", sharedCD.assetBundleKey, req.assetName, req.key, req.isShared);
#endif
                }
                else
                {
#if HUGULA_CACHE_DEBUG
                    int count = CountMananger.WillAdd(keyhash); //引用数量加1
                    HugulaDebug.FilterLogFormat(dep_url, " <color=#fcfcfc> will add  (assetBundle={0},parent={1},hash={2},count={3}) frameCount={4}</color>", dep_url, req.key, keyhash, count, UnityEngine.Time.frameCount);
#else
                    CountMananger.WillAdd(keyhash); //引用数量加1
#endif
                    item              = CRequest.Get();
                    item.relativeUrl  = dep_url;
                    item.isShared     = true;
                    item.async        = req.async;
                    item.priority     = req.priority;
                    item.dependencies = LoadDependencies(item, req);
                    item.uris         = req.uris;
#if HUGULA_LOADER_DEBUG
                    HugulaDebug.FilterLogFormat(req.key, "<color=#15A0A1>1.1  Load Dependencies Req({1},keyHashCode{2})  AssetBundleInternal  Parent Request(assetname={0}), dependencies.count={3},frameCount{4}</color>", req.assetName, item.assetName, item.keyHashCode, item.dependencies == null ? 0 : item.dependencies.Length, Time.frameCount);
#endif

                    LoadAssetBundleInternal(item);
                }
            }

            return(hashs);
        }