示例#1
0
        internal static bool CheckRemove(int keyhashcode)
        {
            float val = 0f;

            if (removeDic.TryGetValue(keyhashcode, out val))
            {
                bool      re    = removeDic.Remove(keyhashcode);
                CacheData cache = CacheManager.TryGetCache(keyhashcode);
#if HUGULA_CACHE_DEBUG
                Debug.LogFormat("<color=#ffff00> -1 remove  abName({0}) for ABDelayUnloadManager ,ref count =  {1},removed={2} </color>", cache.assetBundleKey, cache.count, re);
#endif
                if (cache != null && cache.allDependencies != null)
                {
                    int   keyhash = 0;
                    int[] alldep  = cache.allDependencies;
#if HUGULA_CACHE_DEBUG
                    Debug.LogFormat("<color=#ffff00> -1 remove  abName({0})'s allDependencies from ABDelayUnloadManager , Dependencies.count = {1}  </color>", cache.assetBundleKey, alldep == null?0:alldep.Length);
#endif
                    for (int i = 0; i < alldep.Length; i++)
                    {
                        keyhash = alldep[i];
                        CountMananger.WillAdd(keyhash); //引用数量加1
                        CheckRemove(keyhash);
                    }
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#2
0
        protected static void LoadAssetComplate(CRequest req)
        {
                        #if HUGULA_LOADER_DEBUG
            Debug.LogFormat(" 6. <color=yellow>LoadAssetComplate Req(assetname={0},url={1}) frameCount{2}</color>", req.assetName, req.url, Time.frameCount);
                        #endif
            if (req.isShared)
            {
                CountMananger.Add(req.keyHashCode);
                CountMananger.AddDependencies(req.keyHashCode);
                if (_instance && _instance.OnSharedComplete != null)
                {
                    _instance.OnSharedComplete(req);
                }

                CacheManager.SetAssetLoaded(req.keyHashCode);
                if (req.pool)
                {
                    LRequestPool.Release(req);
                }
            }
            else
            {
                if (req.assetBundleRequest != null)
                {
                    CacheManager.RemoveLock(req.keyHashCode);
                }
                req.DispatchComplete();
                PopGroup(req);
            }
            BeginQueue();
            CheckAllComplete();
        }
示例#3
0
        private static void DispatchReqComplete(CRequest reqitem)
        {
            if (reqitem.isShared)
            {
                CountMananger.Add(reqitem.keyHashCode);
                CountMananger.AddDependencies(reqitem.keyHashCode);
                if (_instance && _instance.OnSharedComplete != null)
                {
                    _instance.OnSharedComplete(reqitem);
                }

                CacheManager.SetAssetLoaded(reqitem.keyHashCode);
                if (reqitem.pool)
                {
                    LRequestPool.Release(reqitem);
                }
            }
            else
            {
                if (reqitem.assetBundleRequest != null)
                {
                    CacheManager.RemoveLock(reqitem.keyHashCode);
                }
                reqitem.DispatchComplete();
                PopGroup(reqitem);
            }
        }
示例#4
0
        /// <summary>
        /// 加载依赖项目
        /// </summary>
        /// <param name="req"></param>
        static protected int[] LoadDependencies(CRequest req)
        {
            string[] deps = assetBundleManifest.GetAllDependencies(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];
                dep_url   = RemapVariantName(depAbName);
                keyhash   = LuaHelper.StringToHash(dep_url);
                hashs[i]  = keyhash;
                if (CacheManager.Contains(keyhash))
                {
                    CountMananger.Add(keyhash);                      //引用数量加1
                }
                else
                {
                    item             = LRequestPool.Get();         //new CRequest(dep_url);
                    item.relativeUrl = dep_url;
                    item.isShared    = true;
                    item.async       = false;
                    //依赖项目
                    string[] depds = assetBundleManifest.GetAllDependencies(item.assetBundleName);
                    if (depds.Length > 0)
                    {
                        int[] hash1s = new int[depds.Length];
                        for (int i1 = 0; i1 < depds.Length; i1++)
                        {
                            depAbName  = depds [i1];
                            dep_url    = RemapVariantName(depAbName);
                            keyhash    = LuaHelper.StringToHash(dep_url);
                            hash1s[i1] = keyhash;
                        }
                        item.allDependencies = hash1s;
                    }
                                        #if HUGULA_LOADER_DEBUG
                    Debug.LogFormat("<color=yellow> Req(assetname={0}) /r/n Begin LoadDependencies Req(assetname={1},url={2}) frameCount{3}</color>", req.assetBundleName, item.assetName, item.url, Time.frameCount);
                                        #endif
                    item.isNormal = req.isNormal;
                    item.uris     = req.uris;
                    AddReqToQueue(item);
                }
            }

            return(hashs);
        }
示例#5
0
        /// <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);
        }
示例#6
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);
        }
示例#7
0
        /// <summary>
        /// load LoadDependencies assetbundle
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        static protected int[] LoadDependencies(CRequest req)
        {
            string[] deps = ManifestManager.fileManifest.GetDirectDependencies(req.assetBundleName);
            if (deps.Length == 0)
            {
                return(null);
            }
#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 = 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  = ManifestManager.RemapVariantName(depAbName);//string gc alloc
                dep_url  = depAbName;
                keyhash  = LuaHelper.StringToHash(dep_url);
                hashs[i] = keyhash;

                CacheData sharedCD = CacheManager.TryGetCache(keyhash);
                if (sharedCD != null)
                {
                    int count = 0;
#if HUGULA_CACHE_DEBUG
                    count = CountMananger.WillAdd(keyhash); //引用数量加1
                    HugulaDebug.FilterLogFormat(req.key + "," + dep_url, " <color=#fcfcfc> will add  (assetBundle={0},hash={1},count={2}) frameCount{3}</color>", dep_url, keyhash, count, UnityEngine.Time.frameCount);
#else
                    count = CountMananger.WillAdd(keyhash); //引用数量加1
#endif
                    bool dependenciesRefer = count == 1;    //the cache count == 0
                    if (dependenciesRefer)
                    {
                        ABDelayUnloadManager.AddDependenciesReferCount(sharedCD, dependenciesRefer);
                    }
#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(req.key + "," + dep_url, " <color=#fcfcfc> will add  (assetBundle={0},hash={1},count={2}) frameCount{3}</color>", dep_url, 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);
                    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);
        }
示例#8
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);
        }