示例#1
0
 /// <summary>
 /// 排队或者加载
 /// </summary>
 /// <param name="req">Req.</param>
 static void QueueOrLoad(CRequest req)
 {
     if (req.isNormal)
     {
         realyLoadingQueue.Enqueue(req);
     }
     else
     {
         CCar car = GetCCar();
         freeLoader.Add(car);
         car.BeginLoad(req);
     }
 }
示例#2
0
 static public int BeginLoad(IntPtr l)
 {
     try {
         Hugula.Loader.CCar     self = (Hugula.Loader.CCar)checkSelf(l);
         Hugula.Loader.CRequest a1;
         checkType(l, 2, out a1);
         self.BeginLoad(a1);
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
示例#3
0
        /// <summary>
        /// 排队或者加载
        /// </summary>
        /// <param name="req">Req.</param>
        static void QueueOrLoad(CRequest req)
        {
#if HUGULA_LOADER_DEBUG
            Debug.LogFormat("  0.2 <color=#15A0A1>QueueOrLoad Request(assetName={0}, url={1},isNormal={2},isShared={3})</color>", req.assetName, req.url, req.isNormal, req.isShared);
#endif
            if (req.isNormal)
            {
                realyLoadingQueue.Enqueue(req);
            }
            else
            {
                CCar car = GetCCar();
                freeLoader.Add(car);
                car.BeginLoad(req);
            }
        }
示例#4
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)
                {
                    freeLoader.RemoveAt(i);
                    ReleaseCCar(load);  //放回对象池
                }
                else
                {
                    i++;
                }
            }

            //1 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();
                }
            }
#if UNITY_EDITOR
            loadingAssetBundleQueueCount = loadingAssetBundleQueue.Count;
            loadingAssetQueueCount       = loadingAssetQueue.Count;
            DebugInfo = "";
#endif
            //2 wait dependencies 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 UNITY_EDITOR
                    DebugInfo += string.Format(" -2.3CheckDependenciesComplete Req(assetname={0},url={1}) frameCount{2},loadingAssetBundleQueue.Count={3}</color>", item.assetName, item.url, Time.frameCount, loadingAssetBundleQueue.Count);
#endif
#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
                }
            }

            //3 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)
                    {
                        if (CacheManager.Typeof_ABAllAssets.Equals(item.assetType))
                        {
                            item.data = ((AssetBundleRequest)item.assetBundleRequest).allAssets;  //赋值
                        }
                        else
                        {
                            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} data{2}) end </color>", item.assetName, item.url, item.data);
#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++;
                }
            }

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

            //group check
            for (int i = 0; i < allGroupRequestRecord.Count;)
            {
                var group = allGroupRequestRecord[i];
                group.Progress();
                if (group.Count > 0)
                {
                    i++;
                }
                else
                {
                    var act = group.onGroupComplate;
                    GroupRequestRecord.Release(group);
                    allGroupRequestRecord.RemoveAt(i);
                    if (act != null)
                    {
                        act(group);
                    }
                }
            }
        }
示例#5
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);
                    }
                }
            }
        }