AddLock() public static method

锁定
public static AddLock ( int hashkey ) : void
hashkey int
return void
Beispiel #1
0
        /// <summary>
        /// 判断异步加载Asset
        /// </summary>
        /// <param name="req"></param>
        static bool CheckLoadAssetAsync(CRequest req)
        {
            if (CacheManager.SetRequestDataFromCache(req))
            {
                if (req.assetBundleRequest != null)
                {
                    CacheManager.AddLock(req.keyHashCode);
                    loadingAssetQueue.Add(req);
                                        #if HUGULA_LOADER_DEBUG
                    Debug.LogFormat("<color=yellow>from cache CheckLoadAssetAsync=true Req(assetname={0},url={1})  </color>", req.assetName, req.url);
                                        #endif
                }
                else
                {
                                        #if HUGULA_LOADER_DEBUG
                    Debug.LogFormat("<color=yellow>from cache CheckLoadAssetAsync=false Req(assetname={0},url={1})  </color>", req.assetName, req.url);
                                        #endif
                    LoadAssetComplate(req);
                }
                return(true);
            }

            return(false);
        }
Beispiel #2
0
        // Update is called once per frame
        void Update()
        {
            //加载
            for (int i = 0; i < loaderPool.Count; i++)
            {
                CCar load = loaderPool[i];
                if (load.isFree && realyLoadingQueue.Count > 0)
                {
                    var req = realyLoadingQueue.Dequeue();
                    if (!CheckLoadAssetBundle(req))
                    {
                        downloadings[req.udKey] = true;
                        load.BeginLoad(req);
                    }
                }
                if (load.enabled)
                {
                    load.Update();
                }
            }

            for (int i = 0; i < freeLoader.Count;)
            {
                CCar load = freeLoader [i];
                if (load.enabled)
                {
                    load.Update();
                }

                if (load.isFree)
                {
                                        #if HUGULA_LOADER_DEBUG
                    if (load.req != null)
                    {
                        Debug.LogFormat(" 1. a <color=yellow>freeLoader is free Req(assetname={0},url={1}) frameCount{2}</color>", load.req.assetName, load.req.url, Time.frameCount);
                    }
                    else
                    {
                        Debug.LogFormat(" 1. a <color=yellow>freeLoader is free Req(assetname={0},url={1}) frameCount{2}</color>", load, load, Time.frameCount);
                    }
                                        #endif
                    freeLoader.RemoveAt(i);
                    ReleaseCCar(load);                      //放回对象池
                }
                else
                {
                    i++;
                }
            }

            //ab
            for (int i = 0; i < loadingAssetBundleQueue.Count;)
            {
                var item = loadingAssetBundleQueue[i];
                if (CacheManager.CheckDependenciesComplete(item))                   //判断依赖项目是否加载完成
                {
                    CacheManager.SetRequestDataFromCache(item);                     //设置缓存数据。
                    loadingAssetQueue.Add(item);
                    if (item.assetBundleRequest != null)
                    {
                        CacheManager.AddLock(item.keyHashCode);                         //异步需要锁定
                    }
                    loadingAssetBundleQueue.RemoveAt(i);
                                        #if HUGULA_LOADER_DEBUG
                    Debug.LogFormat(" 4. <color=yellow>DependenciesComplete Req(assetname={0},url={1}) frameCount{2}</color>", item.assetName, item.url, Time.frameCount);
                                        #endif
                }
                else
                {
                    i++;
                                        #if HUGULA_LOADER_DEBUG
                    Debug.LogFormat(" -4. <color=yellow>CheckDependenciesComplete Req(assetname={0},url={1}) frameCount{2}</color>", item.assetName, item.url, Time.frameCount);
                                        #endif
                }
            }

            //asset
            for (int i = 0; i < loadingAssetQueue.Count; i++)
            {
                var item = loadingAssetQueue[i];
                if (item.assetBundleRequest != null && item.assetBundleRequest.isDone) //如果加载完成
                {
                    if (item.assetBundleRequest is AssetBundleRequest)
                    {
                        item.data = ((AssetBundleRequest)item.assetBundleRequest).asset;//赋值
                    }
                    else
                    {
                        item.data = item.assetBundleRequest;
                    }
                                        #if HUGULA_LOADER_DEBUG
                    Debug.LogFormat(" 5. <color=yellow>set Req(assetname={0},url={1}).data asnyc Count{2} frameCount{3} </color>", item.assetName, item.url, loadingAssetQueue.Count, Time.frameCount);
                                        #endif
                    loadedAssetQueue.Enqueue(item);
                    loadingAssetQueue.RemoveAt(i);
                }
                else if (item.assetBundleRequest == null) //非异步
                {
                    loadedAssetQueue.Enqueue(item);
                    loadingAssetQueue.RemoveAt(i);
                                        #if HUGULA_LOADER_DEBUG
                    Debug.LogFormat(" 5. <color=yellow>set Req(assetname={0},url={1}).data  Count{2} frameCount{3}</color>", item.assetName, item.url, loadingAssetQueue.Count, Time.frameCount);
                                        #endif
                }
                else
                {
                    i++;
                }
            }

            while (loadedAssetQueue.Count > 0)
            {
                LoadAssetComplate(loadedAssetQueue.Dequeue());
            }

            //组进度条
            for (int i = 0; i < allGroupRequestRecord.Count;)
            {
                var group = allGroupRequestRecord [i];
                group.Progress();
                if (group.Count > 0)
                {
                    i++;
                }
                else
                {
                    var act = group.onGroupComplate;
                    GroupRequestRecordPool.Release(group);
                    allGroupRequestRecord.RemoveAt(i);
                    if (act != null)
                    {
                        act(group);
                    }
                }
            }
        }
Beispiel #3
0
        // Update is called once per frame
        void Update()
        {
            for (int i = 0; i < freeLoader.Count;)
            {
                CCar load = freeLoader [i];
                if (load.enabled)
                {
                    load.Update();
                }

                if (load.isFree)
                {
                    // #if HUGULA_LOADER_DEBUG
                    // if(load.req!=null)
                    //  Debug.LogFormat (" 1. a <color=#15C1B2>freeLoader is free Req(assetname={0},url={1}) frameCount{2}</color>", load.req.assetName, load.req.url, Time.frameCount);
                    // else
                    //  Debug.LogFormat (" 1. a <color=#15C1B2>freeLoader is free Req(assetname={0},url={1}) frameCount{2}</color>", load, load, Time.frameCount);
                    // #endif
                    freeLoader.RemoveAt(i);
                    ReleaseCCar(load);                      //放回对象池
                }
                else
                {
                    i++;
                }
            }

            //load assetbunlde
            for (int i = 0; i < loaderPool.Count; i++)
            {
                CCar load = loaderPool[i];
                if (load.isFree && realyLoadingQueue.Count > 0)
                {
                    var req = realyLoadingQueue.Dequeue();
                    if (CheckLoadedAssetBundle(req))
                    {
                        CheckLoadAssetAsync(req);
                    }
                    else if (CheckLoadingAssetBundle(req))
                    {
                        AddReqToQueue(req);
                    }
                    else
                    {
                        downloadings[req.udKey] = load;
                        load.BeginLoad(req);
                    }
                }
                if (load.enabled)
                {
                    load.Update();
                }
            }

            //load set asset
            for (int i = 0; i < loadingAssetBundleQueue.Count;)
            {
                var item = loadingAssetBundleQueue[i];
                if (CacheManager.CheckDependenciesComplete(item))        //判断依赖项目是否加载完成
                {
                    if (CacheManager.SetRequestDataFromCache(item))      //设置缓存数据。
                    {
                        loadingAssetQueue.Add(item);                     //加载资源
                    }
                    else
                    {
                        loadedAssetQueue.Enqueue(item);
                        #if HUGULA_LOADER_DEBUG
                        Debug.LogFormat("<color=red> 2.2 SetRequestDataFromCache false Req(assetname={0},url={1}) frame={2}loadingAssetBundleQueue.Count={3} </color>", item.assetName, item.url, Time.frameCount, loadingAssetBundleQueue.Count);
                        #endif
                    }
                    if (item.assetBundleRequest != null)
                    {
                        CacheManager.AddLock(item.keyHashCode);                         //异步需要锁定
                    }
                    loadingAssetBundleQueue.RemoveAt(i);
                                        #if HUGULA_LOADER_DEBUG
                    Debug.LogFormat(" 2.3 <color=#15C132>DependenciesComplete Req(assetname={0},url={1},async={2}) frameCount{3},loadingAssetBundleQueue.Count={4}</color>", item.assetName, item.url, item.async, Time.frameCount, loadingAssetBundleQueue.Count);
                                        #endif
                }
                else
                {
                    i++;
                                        #if HUGULA_LOADER_DEBUG
                    Debug.LogFormat(" -2.3 <color=#15C132>CheckDependenciesComplete Req(assetname={0},url={1}) frameCount{2},loadingAssetBundleQueue.Count={3}</color>", item.assetName, item.url, Time.frameCount, loadingAssetBundleQueue.Count);
                                        #endif
                }
            }

            //load asset
            for (int i = 0; i < loadingAssetQueue.Count; i++)
            {
                var item = loadingAssetQueue[i];
                #if HUGULA_LOADER_DEBUG
                Debug.LogFormat(" 3.2.-1 <color=#A9C115> Req(assetname={0},url={1}) loadingAssetQueue.Count={2} frameCount{3} </color>", item.assetName, item.url, loadingAssetQueue.Count, Time.frameCount);
                                #endif
                if (item.assetBundleRequest != null && item.assetBundleRequest.isDone) //如果加载完成
                {
                    #if HUGULA_LOADER_DEBUG
                    Debug.LogFormat(" 3.2.0 <color=#A9C115>set Req(assetname={0},url={1}).data asnyc Count{2} frameCount{3} </color>", item.assetName, item.url, loadingAssetQueue.Count, Time.frameCount);
                                        #endif
                    if (item.assetBundleRequest is AssetBundleRequest)
                    {
                        item.data = ((AssetBundleRequest)item.assetBundleRequest).asset;//赋值
                    }
                    else
                    {
                        item.data = item.assetBundleRequest;
                    }
                    #if HUGULA_LOADER_DEBUG
                    Debug.LogFormat(" 3.2.1 <color=#A9C115>set Req(assetname={0},url={1} abr{2}).data end </color>", item.assetName, item.url, item.assetBundleRequest);
                                        #endif
                    loadedAssetQueue.Enqueue(item);
                    loadingAssetQueue.RemoveAt(i);
                }
                else if (item.assetBundleRequest == null) //非异步
                {
                    loadedAssetQueue.Enqueue(item);
                    loadingAssetQueue.RemoveAt(i);
                                        #if HUGULA_LOADER_DEBUG
                    Debug.LogFormat(" 3.2 <color=#A9C115>set Req(assetname={0},url={1}).data Async  Count{2} frameCount{3}</color>", item.assetName, item.url, loadingAssetQueue.Count, Time.frameCount);
                                        #endif
                }
                else
                {
                    i++;
                }
            }

            //complete
            while (loadedAssetQueue.Count > 0)
            {
                LoadAssetComplate(loadedAssetQueue.Dequeue());
            }

            //组进度条
            for (int i = 0; i < allGroupRequestRecord.Count;)
            {
                var group = allGroupRequestRecord [i];
                group.Progress();
                if (group.Count > 0)
                {
                    i++;
                }
                else
                {
                    var act = group.onGroupComplate;
                    GroupRequestRecordPool.Release(group);
                    allGroupRequestRecord.RemoveAt(i);
                    if (act != null)
                    {
                        act(group);
                    }
                }
            }
        }