Example #1
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);
        }
Example #2
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);
        }